场景
Commands out of sync; you can't run this command now
复现
$db->execute('BEGIN');
$result = $db->multi_query("call SP_JIT_CALCULATE_SYN_STOCK(1526,0)");
if (!$result) {
$error_msg = $db->error_msg();
echo "error_msg: " . $error_msg . PHP_EOL;
$db->execute('ROLLBACK');
return false;
}
$row = $db->query_result('select @sys_code,@sys_message');
if ($row["@sys_code"] != 0 || $row["@sys_code"] === null){
$error_msg = $row['@sys_message'];
echo "error_msg2: " . $error_msg . PHP_EOL;
return false;
}
$jitCalcSynStock = $db->fetch_array($result);
$db->free_result($result);
$db->execute('COMMIT');
分析
This can happen, for example, if you are using mysql_use_result() and try to execute a new query before you have called mysql_free_result(). It can also happen if you try to execute two queries that return data without calling mysql_use_result() or mysql_store_result() in between.
- 很明显是连续执行multi_query query_result导致,在执行query_result之前执行mysql_free_result释放前一个query
修复
$db->execute('BEGIN');
$result = $db->multi_query("call SP_JIT_CALCULATE_SYN_STOCK(1526,0)");
if (!$result) {
$error_msg = $db->error_msg();
echo "error_msg: " . $error_msg . PHP_EOL;
$db->execute('ROLLBACK');
return false;
}
$jitCalcSynStock = $db->fetch_array($result);
$db->free_result($result);
$row = $db->query_result('select @sys_code,@sys_message');
if ($row["@sys_code"] != 0 || $row["@sys_code"] === null){
$error_msg = $row['@sys_message'];
echo "error_msg2: " . $error_msg . PHP_EOL;
return false;
}
$db->execute('COMMIT');