dousi7579 2016-09-22 14:32
浏览 89
已采纳

使用PHP / MySQLi进行多次UPDATE和INSERT

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 'mysqli_free_result()' after every single one?

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. 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.

  • 写回答

1条回答 默认 最新

  • douyazi1129 2016-09-22 14:39
    关注

    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

    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().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度