无法在Multi MYSQL查询语句

时间:2016-09-24 14:58:10

标签: php 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';
}

返回'无结果'

enter image description here

请告知。

== SOLUTION ==

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>';

1 个答案:

答案 0 :(得分:1)

尝试为每个语句进行一次查询。一个用于SET,一个用于UPDATE,一个用于SELECT。

ETA:因为SET我猜这不行。您需要改为使用multi_query