I got this Code:
// Some starting variables
$test = new mysqli("localhost","root","","testdatabase");
$Query = array();
$Query[] = "SELECT 'wos' FROM items WHERE itemID = 3";
$Query[] = "SELECT 'wos' FROM items WHERE itemID";
$Query[] = "SELECT 'wos' FROM items WHERE itemID = 5";
$Query = implode(";",$Query);
$Errors = array();
// Execute multi query
if ($test->multi_query($Query)) {
do {
// fetch results
$Result = $test->store_result();
print_r($Result);
if($test->errno === 0) {
echo $Result->num_rows . "<br>";
}
else {
$Errors[] = $test->error;
}
$Result->close();
if (!$test->more_results()) {
break;
}
if (!$test->next_result()) {
$Errors[] = $test->error;
break;
}
} while (true);
}
As you can see I have a number of X subsequent queries and want to perform them all. So if query 2 fails I want to continue the multi-query to let the following queries run. How can I do this?
Also, if an error occurs I want to save this error in $Errors
. However, currently it isn't quite working as intended since I can only save the error message but not the corresponding query. Only the error message isn't really helpful without the query which failed. So I want to have something like: "Query 3 failed ('SELECT ...'): 'ERROR MESSAGE'"
.
How is this possible? I am able to get the current error in the loop with $test->error
, but I don't have anything like $test->currentsubsequentquery
. How can I do that?