mysql执行存储过程提示out of_PHP执行MYSQL存储过程报错:Commands out of sync; you can't run...
php中在同時(shí)執(zhí)行2個(gè)存儲(chǔ)過程時(shí),有一個(gè)程序2個(gè)儲(chǔ)存過程都執(zhí)行,有一個(gè)程序只執(zhí)行第一個(gè)調(diào)用。2個(gè)都執(zhí)行的調(diào)用如下:
$mydb->query("delete from pinfo where id in(" . $id .
")");
SaveLog($Ptype, $_SESSION["username"]. " Delete ".$Ptype." [ID=" .
$id . "]");
只有第一個(gè)存儲(chǔ)過程執(zhí)行的程序如下:
$uresult = $mydb->query("call
Addnews('".$strname."','".$source."','".$strtitle."','".$strContent."','".time()."',@uresult)");
SaveLog($Ptype, $_SESSION["username"]. " Add ".$Ptype." [title=" .
$strtitle . "]");
$nResult = mysql_fetch_row($uresult);
$nResult = $nResult[0];
其中函數(shù)SaveLog內(nèi)容如下:
Function SaveLog($strMessageType,$strMsg)
{?mysql_query("call
SaveManageLog('".$strMessageType."','".strFilter($strMsg).
"',".time().")");?}
把不執(zhí)行第2個(gè)儲(chǔ)存過程的echo出來,放在mysql里單獨(dú)是可執(zhí)行的。那么問題出在那呢?
mysql_query($command) or die(msyql_error())
把mysql_query后加上 or die(msyql_error())顯示錯(cuò)誤,提示Commands out of
sync; you can't run this command now
解決如下:
$mysqli = new
mysqli("localhost", "root", "sbqcel", "test");
$mysqli->multi_query("call
Addnews('".$strname."','".$source."','".$strtitle."','".$strContent."','".time()."',@uresult)");?$uresult
=$mysqli->store_result();
$nResult =
$uresult->fetch_row();
$uresult->close();
$mysqli->close();
SaveLog($Ptype,
$_SESSION["username"]. " Add ".$Ptype." [title=" . $strtitle .
"]");
現(xiàn)在2個(gè)存儲(chǔ)過程都可以執(zhí)行了。注意:如果第一個(gè)調(diào)用返回值,那么第2個(gè)就不能執(zhí)行,這里就要用到mysql的mysqli
總結(jié)
以上是生活随笔為你收集整理的mysql执行存储过程提示out of_PHP执行MYSQL存储过程报错:Commands out of sync; you can't run...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php pdo 绕过,php-带PDO的
- 下一篇: mysql源码_MySql轻松入门系列—