mysqli

mysqli why does this happens?

爷,独闯天下 提交于 2020-01-30 10:25:08
问题 I have two subsequent mysqli statements, and the second returns: Fatal error: Call to a member function bind_param() on a non-object in ... Why this happens? Does this means that I need to open two different connection? Is there any way to avoid this (I love keeping the SQL connection details in one file)? Here the code: $db = new mysqli("localhost", "root", "", "database"); $stmt = $db->prepare("UPDATE posts SET vote_".$_POST['vote']." = vote_".$_POST['vote']." + 1 WHERE id=?"); $stmt->bind

MySQLi export table to CSV

筅森魡賤 提交于 2020-01-30 08:19:08
问题 I've been trying for many days to export from a query some values in .csv with MySQLi, but I have a problem when the export is made, everything is exporting to a single column, instead I need that the export should make like SQL code (I have 3 selected columns and I need 3 exported columns in .cvs ). Bellow you can find two codes: 1) This code creates a data base, table and insert the values: <?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "myDB"; // Create

MySQLi export table to CSV

笑着哭i 提交于 2020-01-30 08:19:05
问题 I've been trying for many days to export from a query some values in .csv with MySQLi, but I have a problem when the export is made, everything is exporting to a single column, instead I need that the export should make like SQL code (I have 3 selected columns and I need 3 exported columns in .cvs ). Bellow you can find two codes: 1) This code creates a data base, table and insert the values: <?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "myDB"; // Create

Automatcially check checkbox based on database array PHP

十年热恋 提交于 2020-01-30 06:42:18
问题 In the "User Setting" tab of my page, I want the user to determine which types of posts from a specific user. Here is the form: <form method="post" action="" name="permitted_categories"> Select or deselect which types of Posts that you would like to see. <p> <? $cat_query = mysqli_query($con, "SELECT permitcat FROM permitted WHERE username='$userLoggedIn' AND friendname='$username'") ?> <label> <input type="checkbox" name="categories[]" value="Life" id="Life" <? echo $checked;?>> Life</label>

Mysqli can't insert multiple rows

╄→гoц情女王★ 提交于 2020-01-30 02:44:28
问题 $allgames = file_get_contents("https://steamspy.com/api.php?request=all"); $decodeall = json_decode($allgames, true); foreach($decodeall as $game) { $sql = "INSERT INTO games (name) VALUES ('{$game['name']}')"; } if ($conn->multi_query($sql) === TRUE) { echo "New records created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); When i do this only the first row will be added. How do i insert multiple rows? 回答1: Just get rid of that multi query thing. Use

a permanent way of doing mysqli->set_charset()?

泪湿孤枕 提交于 2020-01-29 00:52:15
问题 after setting all config file and runtime options for charset that i can find to utf-8, new mysqli connections made with php still has its charset set to latin1, which effectively means that i have to call $mysqli->set_charset('utf8') each time i connect. $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME); if ($mysqli->connect_error) err_handle("mysql connect error({$mysqli->connect_errno})."); if (!$mysqli->set_charset("utf8")) err_handle("db error({$mysqli->errno})."); i wonder if

Will a mysql transaction work if multiple connections are used for the queries?

霸气de小男生 提交于 2020-01-28 11:10:39
问题 So here it is ... // I start transaction $mysqli = new mysqli(...); // Start transaction $mysqli->autocommit(FALSE); here is a select prepared stmt with its own db connection here is an insert prepared stmt with its own db connection here is an slect prepared stmt with the above db conn insert new conn insert new conn insert new conn if every prepared query returs true it will($mysqli->commit()) else $mysqli->rollback I dont know for what reason that transaction will autocommit I've done some

mysqli_fetch_assoc() expects parameter / Call to a member function bind_param() errors. How to get the actual mysql error and fix it?

 ̄綄美尐妖づ 提交于 2020-01-26 04:41:06
问题 In my local/development environment, the MySQLi query is performing OK. However, when I upload it on my web host environment, I get this error: Fatal error: Call to a member function bind_param() on a non-object in... Here is the code: global $mysqli; $stmt = $mysqli->prepare("SELECT id, description FROM tbl_page_answer_category WHERE cur_own_id = ?"); $stmt->bind_param('i', $cur_id); $stmt->execute(); $stmt->bind_result($uid, $desc); To check my query, I tried to execute the query via

Inserting Data in mysqli is not working

 ̄綄美尐妖づ 提交于 2020-01-25 23:45:29
问题 I am wondering why my insert statement does not work. There are no records shown in the database and it does not show any errors. Here is the code <?php if(isset($_POST['submit'])){ $username = trim($_POST['username']); $password = trim($_POST['password']); $conf_pass = trim($_POST['conf_password']); $email = trim($_POST['email']); require_once('./includes/Db/CheckPassword.php'); $check_pwd = new Db_CheckPassword($password); $passwordOK =$check_pwd->check(); $password_match = Db_CheckPassword

Inserting Data in mysqli is not working

纵饮孤独 提交于 2020-01-25 23:44:46
问题 I am wondering why my insert statement does not work. There are no records shown in the database and it does not show any errors. Here is the code <?php if(isset($_POST['submit'])){ $username = trim($_POST['username']); $password = trim($_POST['password']); $conf_pass = trim($_POST['conf_password']); $email = trim($_POST['email']); require_once('./includes/Db/CheckPassword.php'); $check_pwd = new Db_CheckPassword($password); $passwordOK =$check_pwd->check(); $password_match = Db_CheckPassword