bluewater_sailor bluewater_sailor - 1 year ago 41
MySQL Question

Multiple UPDATEs and INSERTs with PHP/MySQLi

I need to reconcile between an existing set of tables and new/changed information that I get on a regular basis, and so have a set of ~30 UPDATE/INSERT operations that has to run every time. Since 'mysql_query' is now deprecated, and I'd prefer not to recode everything in OO, is there a reasonable procedural way to run all of these in sequence without having to call '

' after every single one?

Just for the record, I've tried running them as a set of
statements without
, and it's a mess: some of the operations go through while others fail silently. Frankly, a shell script with a bunch of '
mysql -e
' commands in it was much more reliable... but this needs to be a Web-driven app, so that's not viable anymore.

Answer Source

Your assumptions are wrong.

mysqli_query's behavior is similar to one of mysql_query and you don't need any other modifications. neither mysqli_free_result() is related to your problem.

the only meaningful part of your question is queries that fails silently. To make them fail noisily, just tell mysqli to do so. add this line before mysqli_connect


and the first query that fails will tell you the reason.

but in general, there is not a single problem with running multiple UPDATE and INSERT queries using mysqli_query().