简体   繁体   English

使用PHP / MySQLi的多个UPDATE和INSERT

[英]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. 我需要在一组现有的表和我定期获得的新的/更改的信息之间进行协调,因此必须有一组〜30每次必须运行的UPDATE / INSERT操作。 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 ' mysqli_free_result() ' after every single one? 由于现在不建议使用“ mysql_query”,并且我不希望在OO中重新编码所有内容,是否有一种合理的过程方法来按顺序运行所有这些,而不必在每个命令之后都调用“ mysqli_free_result() ”?

Just for the record, I've tried running them as a set of mysqli_query statements without mysqli_free_result() , and it's a mess: some of the operations go through while others fail silently. 仅作记录,我尝试将它们作为一组mysqli_query语句(不带mysqli_free_result() ,这很麻烦:有些操作会通过,而另一些操作会静默失败。 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. 坦白地说,其中包含一堆“ mysql -e ”命令的shell脚本要可靠得多……但这需要是一个Web驱动的应用程序,因此不再可行。

Your assumptions are wrong. 您的假设是错误的。

mysqli_query's behavior is similar to one of mysql_query and you don't need any other modifications. mysqli_query的行为类似于mysql_query之一,您不需要任何其他修改。 neither mysqli_free_result() is related to your problem. mysqli_free_result()都与您的问题无关。

the only meaningful part of your question is queries that fails silently. 问题中唯一有意义的部分是无提示失败的查询。 To make them fail noisily, just tell mysqli to do so. 要使它们吵闹,只需告诉mysqli这样做即可。 add this line before mysqli_connect 在mysqli_connect之前添加此行

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

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(). 但是通常,使用mysqli_query()运行多个UPDATE和INSERT查询不会有一个单一的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM