0

Using PHP and mysqli_multi_query to create tables in database and insert some values. The code is below:

mysqli_multi_query($GLOBALS["mysqli"], $mysql_query) or die(mysqli_error($GLOBALS["mysqli"]));

The problem is that when invalid $mysql_query is used, it doesn't return any errors. For example, if $mysql_query looks like:

INSERT INTO table (col, col2) VALUES ('val1', 'val2', 'val3');

it doesn't die (and doesn't display any errors), but no data is inserted to the table of course. I need to copy/paste the same code into phpmyadmin to see what the error is. It ONLY dies if ABSOLUTELY INVALID query is used (like $mysql_query="abc123errorwhatever")

And even if I add text 'abc123errorwhatever' at the end of some valid query; it doesn't die too. No errors, nothing.

Mindaugas Li
  • 1,071
  • 5
  • 15
  • 37
  • if you want errors from individual queries, then don't use multi_query. fire off individual SINGLE query() calls and check for errors after each one. – Marc B Jan 26 '16 at 17:06
  • Do you mean that if multi-query has some errors, mysqli_multi_query should NOT display errors as long as at least one of queries is valid? – Mindaugas Li Jan 26 '16 at 17:10
  • it's by far easier to check for errors by doing individual queries. with multi_query, you have to do a looped store_result and check mysqli_error() anyways. – Marc B Jan 26 '16 at 17:11
  • The fact is that $mysql_query is received as string from remote server, and I'm not very excited about converting received string into an array (separating each single query) and then executing queries one after one. I know it's not difficult, but I simply prefer using multi_query – Mindaugas Li Jan 26 '16 at 17:13
  • that's pretty scary - acceping raw sql from "outside". hopefully no one can stuff a `drop database database()` in there... – Marc B Jan 26 '16 at 19:45
  • Cast your eyes on this answer for some basic/general suggestions: http://stackoverflow.com/questions/14715889/strict-standards-mysqli-next-result-error-with-mysqli-multi-query/22469722#22469722 – mickmackusa Nov 15 '16 at 14:03

0 Answers0