Working in PHP and using MYSQLI. Trying to get the insert_id for all rows inserted from a single insert query with multiple values. Keeping it in a single call for efficiency. My actual code has hundreds of values in one insert query. However, here is some sample code for an insert with just 4 values: The above code achieves the
Tag: mysqli
new mysqli(): how to intercept an ‘unable to connect’ error?
I’m doing this (yes, I’m using wrong connection data, it’s to force a connection error ) try { $connection = new mysqli(‘localhost’, ‘my_user’, ‘my_password’, ‘my_db’) ; } catch (Exception $e ) { …
Best way to INSERT many values in mysqli?
I’m looking for a SQL-injection-secure technique to insert a lot of rows (ca. 2000) at once with PHP and MySQLi. I have an array with all the values that have to be include. Currently I’m doing that: I tried call_user_func_array(), but it caused a stack overflow. What is a faster method to do this (like inserting them all at once?),
Custom mysqli prepare function
I’m doing my first own database class at the moment and currently I’m doing the prepare function. What this function does is to take in an SQL-query and then an array containing the variables for the …
mysql sanitize row name
I’m currently writing a php framework with focus on security. I use a query builder to generate SQL-statements, so that it is not bound to MySQL. (Or SQL in general) I found certain posibilities that user could inject row names, so it has to escape them somehow. Because of how the query builder works, i sadly cannot use prepared statements.
bind_param Number of variables doesn’t match number of parameters in prepared statement
Here is a snippet from my code: When I echo out the values for $year and $make, I am seeing values, but when I run this script, I get a null value, and the following warning appears in my log file: PHP Warning: mysqli_stmt::bind_param(): Number of variables doesn’t match number of parameters in prepared statement In this case, year is
Database Driver MySQLi Error
I am running Moodle test environment on Window Vista having PHP 5.2.10 and MySQL 5.1.36-Community. When I upgrade from Moodle 1.9.9 to 2.0, I am getting the following error. I also tried to change the dbtype=’mysqli’ in config.ini and still see same error. I would really appreciate if you can provide some suggestion to resolve this error. Thank you in
How to get the SQL_CALC_FOUND_ROWS value using prepared statements?
I’m currently scratching my head at how to implement SQL_CALC_FOUND_ROWS with prepared statements. I’m writing a pagination class and obviously i want to add LIMIT to the query but also find what the …
Couldn’t fetch Mysqli_result
I’ve got this error Warning: mysqli_fetch_array() [function.mysqli-fetch-array]: Couldn’t fetch mysqli_result in /home/fights7/public_html/include/load_more_home_posts.php on line 12 And would like to know what I’ve done wrong with the below code? Answer Straight away, it appears that you are calling mysqli_free_result() inside your fetch loop, so after the first loop iteration, your result resource has been closed and freed, and no more results
How to identify the query that caused the error using mysqli_multi_query?
Using a example from elsewhere on SO to better catch ‘hiding’ errors. While the code below will catch and return an error, is it possible to improve this to report for which query the error occurred? With the code below, the output is: Code being tested: Answer Here is an approach that will not only improve the quality of your