php - 执行mysql存储过程后Commands out of sync; you can't run this command now
PHPz
PHPz 2017-04-10 14:29:03
[PHP讨论组]

php调用存储过程后再执行sql就提示Commands out of sync; you can't run this command now,请问是什么问题?

PHPz
PHPz

学习是最好的投资!

全部回复(1)
迷茫

要解决这个问题,需要用mysqli的multi_query方法

<?php
$mysqli = new mysqli("localhost", "root", "sbqcel", "test");

if (mysqli_connect_errno()) 
{
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
echo 'result1:<br />';
$mysqli->autocommit(FALSE);
if ($mysqli->multi_query("call test1();")) 
{
    do {
        if ($result = $mysqli->store_result()) {
            while ($row = $result->fetch_row()) {
                printf("%s\n", $row[0]);
            }
            $result->close();
        }
    } while ($mysqli->next_result());
}
$mysqli->commit();
echo "<br />";
echo "result2:<br />";
if ($result2 = $mysqli->query("select val from tb1;")) 
{
    while ($row = $result2->fetch_row()) {
        printf ("%s <br />", $row[0]);
    }
    $result2->close();
}
else
{
    echo $mysqli->error;
}
$mysqli->close();
?> 
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号