php中在同时执行2个存储过程时,有一个程序2个储存过程都执行,有一个程序只执行第一个调用。2个都执行的调用如下:
$mydb->query("delete from pinfo where id in(" . $id .
")");
SaveLog($Ptype, $_SESSION["username"]. " Delete ".$Ptype." [ID=" .
$id . "]");
只有第一个存储过程执行的程序如下:
$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];
其中函数SaveLog内容如下:
Function SaveLog($strMessageType,$strMsg)
{ mysql_query("call
SaveManageLog('".$strMessageType."','".strFilter($strMsg).
"',".time().")"); }
把不执行第2个储存过程的echo出来,放在mysql里单独是可执行的。那么问题出在那呢?
mysql_query($command) or die(msyql_error())
把mysql_query后加上 or die(msyql_error())显示错误,提示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 .
"]");
现在2个存储过程都可以执行了。注意:如果第一个调用返回值,那么第2个就不能执行,这里就要用到mysql的mysqli