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

I am trying to run a fairly large number of updates / inserts in a table using multi_query. There are ~ 14,000 requests in total, but the function only executes ~ 480, and then stops without errors, and PHP continues the script outside of the snippet:

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);
}else{
    $this->message->set('Import could not be completed. '.mysqli_error($this->db->conn_id),'error',TRUE);
}
+5
source share
1 answer

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

, mysqli:: next_result() false , " ". , , , .

, , , .

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

All Articles