dongzhong7443 2013-07-10 09:15
浏览 65
已采纳

PHP使用MySQL'mysqli_multi_query'不止一次?

Trying to execute following PHP code, however just first statement gets executed successfully and rest following don't.

<?php

$link = mysqli_connect('localhost', 'root', '');
mysqli_select_db($link, 'database_name');


$update = " UPDATE `temp` SET `price` = 1000 WHERE `id` = 1;
            UPDATE `temp` SET `price` = 2000 WHERE `id` = 2;
            UPDATE `temp` SET `price` = 3000 WHERE `id` = 3;
            UPDATE `temp` SET `price` = 4000 WHERE `id` = 4;
            UPDATE `temp` SET `price` = 5000 WHERE `id` = 5;";

mysqli_multi_query($link, $update);

$update2 = "UPDATE `temp` SET `price` = 6000 WHERE `id` = 6;
            UPDATE `temp` SET `price` = 7000 WHERE `id` = 7;
            UPDATE `temp` SET `price` = 8000 WHERE `id` = 8;
            UPDATE `temp` SET `price` = 9000 WHERE `id` = 9;
            UPDATE `temp` SET `price` = 10000 WHERE `id` = 10;";

mysqli_multi_query($link, $update2);

?>

mysqli_multi_query($link, $update); - Executed Successfully

mysqli_multi_query($link, $update2); - Not Executed.

Could anybody guide, if I might be missing something, or regarding the syntax.

  • 写回答

4条回答 默认 最新

  • dsozqcx9668 2013-07-10 15:03
    关注

    You have to fetch all results - for example:

    // here: first multi query
    
    // fetch all results
    while( mysqli_more_results($link) ){
        $result = mysqli_store_result($link);
        mysqli_next_result($link);
    }
    
    // here: second multi query
    

    Some SQL systems in some languages are "lazy". They send query only when you ask for results (for example LINQ in C#). Maybe PHP do the same. It blocks connection waiting for your result fetching.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面