开发者

Why does mysqli::multi_query stop after a certain amount of rows?

开发者 https://www.devze.com 2023-02-05 19:38 出处:网络
I\'m attempting to run a fairly large amount of updates/inserts on a table using multi_query. There are ~14,000 queries total, but the function only executes ~480, then it stops without errors and PHP

I'm attempting to run a fairly large amount of updates/inserts on a table using multi_query. There are ~14,000 queries total, but the function only executes ~480, then it stops without errors and PHP continues the script beyond the snip below:

if($this->db->conn_id->multi_query($sql)){
    do{
        // echo $line.' '.mysqli_sqlstate($this->db->conn_id).'<br>';
    }while($this->db->conn_id->more_results() && $this->db->conn_id->next_result());
    $this->message->set('Import complete.','success',TRUE开发者_如何学Python);
}else{
    $this->message->set('Import could not be completed. '.mysqli_error($this->db->conn_id),'error',TRUE);
}


mysqli::multi_query only returns false if the first statement fails. To get the errors from the other queries in your set, you need to call mysqli::next_result() first, which is what your do while() is doing.

However, since mysqli::next_result() returns false on failure, it will cause the loop to end and the 'Import complete' message to be displayed. You probably need to check for an error before setting the success message, and only if the error is blank, return success.

The following should at least show you the error if there was one later in the statement.

if($this->db->conn_id->multi_query($sql)){
    do{
        // echo $line.' '.mysqli_sqlstate($this->db->conn_id).'<br>';
    } while($this->db->conn_id->more_results() && $this->db->conn_id->next_result());

    if ($error = mysqli_error($this->db->conn_id)) {
        $this->message->set('Import could not be completed. ' . $error,'error',TRUE);
    } else $this->message->set('Import complete.','success',TRUE);
} else {
    $this->message->set('Import could not be completed. '.mysqli_error($this->db->conn_id),'error',TRUE);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消