In my db I have some stored procedures.
I want to call the one of them, and according to the results I get from this procedure, i will determine weather to call the
Every stored procedure returns at least two results
You have to use mysqli_more_results()
/mysqli_next_result()
to clean them.
If your procedure returns only one result, or you just don't want any extra results but the first one, you can clean up the results queue with this code snippet:
while($mysqli->more_results())
{
$mysqli->next_result();
if($res = $mysqli->store_result())
{
$res->free();
}
}
re connect database $this->db->reconnect(); // likes in codeigniter
The currently accepted answer wont work as-is, i think next_result()
should not be called before the first result.
This is an example that does work:
if (!$mysqli->multi_query("CALL p()")) {
echo "CALL failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
do {
if ($res = $mysqli->store_result()) {
printf("---\n");
var_dump($res->fetch_all());
$res->free();
} else {
if ($mysqli->errno) {
echo "Store failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
}
} while ($mysqli->more_results() && $mysqli->next_result());
From the PHP manual http://php.net/manual/en/mysqli.quickstart.stored-procedures.php