5

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);
}else{
    $this->message->set('Import could not be completed. '.mysqli_error($this->db->conn_id),'error',TRUE);
}
Erik
  • 302
  • 2
  • 12

1 Answers1

0

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);
}
cmendoza
  • 296
  • 1
  • 4
  • Actually, there are no errors in the queries themselves. I'm passing in the contents of a sql file and it runs fine via command line or gui tool. – Erik Jan 26 '11 at 04:08