php – 无法在Multi MYSQL查询语句中获取结果

==已解决==

我从以下帖子中获得此查询:

How to get ID of the last updated row in MySQL?

我在phpMyAdmin上试了一下,看到了我想要但无法获取的结果.

$query = "SET @order_id := '', @order_token := '', @order_param := ''; UPDATE transaction set `ts_status` = 'completed', `ts_remarks` = '', `tsid` = (SELECT @order_id := tsid), `token` = (SELECT @order_token := token), `param` = (SELECT @order_param := param) WHERE `token` = '503cd5c095fa942dbdfe72b2f4302edf' LIMIT 1; SELECT @order_id as order_id, @order_token as order_token,  @order_param as order_param";

if($result = $con->query($query)){
  $row = $result->fetch_array();
} else {
 echo 'no result';
}

它返回’没有结果’

《php – 无法在Multi MYSQL查询语句中获取结果》

请指教.

==解决方案==

if (!$con->multi_query($query)) {
    echo "Multi query failed: (" . $mysqli->errno . ") " . $mysqli->error;
}

do {
    if ($res = $con->store_result()) {
        $row = $res->fetch_all(MYSQLI_ASSOC);
        $res->free();
    }
} while ($con->more_results() && $con->next_result());
echo '<pre>';
print_r($row);
echo '</pre>';

最佳答案 尝试为每个语句进行一次查询.一个用于SET,一个用于UPDATE,一个用于SELECT.

ETA:因为SET我猜这不行.你需要使用multi_query.

点赞