mysqli

MySQL PDO Name-Value Prepared Statement Using Last Parameter Only

丶灬走出姿态 提交于 2020-12-23 12:22:48
问题 As titled, I'm using MySQL PDO with a prepared statement, and when executing, I'm getting a single value (the last supplied value) pushed into all fields. Table looks like so: id (int - auto-increment) a_id (int) b_id (int) INSERT looks like this: INSERT INTO my_table(a_id, b_id) VALUES (:a_id, :b_id) Code to insert looks like this... $stmt = $conn->prepare($sql); foreach($params as $k => $v) { $stmt->bindParam( $k, $v ); } $stmt->execute(); The statement successfully inserts a value (which

MySQL PDO Name-Value Prepared Statement Using Last Parameter Only

旧时模样 提交于 2020-12-23 12:20:45
问题 As titled, I'm using MySQL PDO with a prepared statement, and when executing, I'm getting a single value (the last supplied value) pushed into all fields. Table looks like so: id (int - auto-increment) a_id (int) b_id (int) INSERT looks like this: INSERT INTO my_table(a_id, b_id) VALUES (:a_id, :b_id) Code to insert looks like this... $stmt = $conn->prepare($sql); foreach($params as $k => $v) { $stmt->bindParam( $k, $v ); } $stmt->execute(); The statement successfully inserts a value (which

MySQL PDO Name-Value Prepared Statement Using Last Parameter Only

烈酒焚心 提交于 2020-12-23 12:20:35
问题 As titled, I'm using MySQL PDO with a prepared statement, and when executing, I'm getting a single value (the last supplied value) pushed into all fields. Table looks like so: id (int - auto-increment) a_id (int) b_id (int) INSERT looks like this: INSERT INTO my_table(a_id, b_id) VALUES (:a_id, :b_id) Code to insert looks like this... $stmt = $conn->prepare($sql); foreach($params as $k => $v) { $stmt->bindParam( $k, $v ); } $stmt->execute(); The statement successfully inserts a value (which

PHP singleton database connection pattern

混江龙づ霸主 提交于 2020-12-23 01:51:07
问题 I've been working on a small project using PHP and MySQL. I've read a lot around about best practices on managing a connection and so on. I've also implemented (following some posts found around) a singleton class to manage MySQL connections. require_once 'config.inc.php'; class DbConn { private static $instance; private $dbConn; private function __construct() {} /** * * @return DbConn */ private static function getInstance(){ if (self::$instance == null){ $className = __CLASS__; self::

What is the best way to minimize number of connections?

╄→尐↘猪︶ㄣ 提交于 2020-12-21 02:04:12
问题 My host has a really, really low number of max connections for a database user. This is the error my users are getting: User 'username_here' has exceeded the 'max_user_connections' resource (current value: 15). I don't think it's in my power to raise that value, unless I upgrade to a much more expensive plan, so I'm looking for a way to use these 15 connections effectively. My way of handling connections is the following: I connect to the database in a script I load at the start of every page

mysqli_multi_qry wait for the output of the query before calling it again

被刻印的时光 ゝ 提交于 2020-12-15 03:44:32
问题 I have a code below that creates a multi qry $sql_multi = ""; for ($branch_index = 0; $branch_index < count($branch_ids); $branch_index++) { for ($item_index = 0; $item_index < count($item_ids); $item_index++) { $item_id = $item_ids[$item_index]; $branch_id = $branch_ids[$branch_index]; $sql_multi .= "CALL sp_pivot_qty_eb(".$item_id.",".$branch_id.",'".$_GET["to"]."');"; } } /* execute multi query for qty */ if ($con->multi_query($sql_multi)) { do { $result = $con->store_result(); while (

mysqli_multi_qry wait for the output of the query before calling it again

橙三吉。 提交于 2020-12-15 03:43:23
问题 I have a code below that creates a multi qry $sql_multi = ""; for ($branch_index = 0; $branch_index < count($branch_ids); $branch_index++) { for ($item_index = 0; $item_index < count($item_ids); $item_index++) { $item_id = $item_ids[$item_index]; $branch_id = $branch_ids[$branch_index]; $sql_multi .= "CALL sp_pivot_qty_eb(".$item_id.",".$branch_id.",'".$_GET["to"]."');"; } } /* execute multi query for qty */ if ($con->multi_query($sql_multi)) { do { $result = $con->store_result(); while (

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

大城市里の小女人 提交于 2020-12-15 01:54:57
问题 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

Execute simple mysqli query on click with AJAX

戏子无情 提交于 2020-12-13 11:56:22
问题 My AJAX/Java knowledge is very limited so this might sound like a stupid and very easy question, but here I go. I am trying to execute a very simple one line mysqli query after clicking a link on a php page. This query has to be executed in the background, so without reloading the page, so I would need AJAX to do that. EDIT: This is the code I have now. The PHP page (notes_checked.php) with my query: if ($user_ok == true) { mysqli_query($db_conx, "UPDATE users SET notescheck=now() WHERE

Database abstraction layer ontop of mysqli

末鹿安然 提交于 2020-12-13 07:20:22
问题 when trying to build robust database code (table locking, transactions, etc) i am always annoyed by the mass of code that needs to be done. For example a transaction out of two prepared statements where i want to delete a user and update something about him in an "actions" table: Lock Table users, actions Start a transaction (autocommit false) Make a prepared statement for the deletion of a user Check if statement is != false (cause it could have already failed at 3. Bind param Check