28/02/2013 0 Commands out of sync; you can't run this command now | |
Mots-clés: MySQL PHP Procédures stockées | |
L'appel à une procédure stockée crée 2 résults set qui doivent être tous les deux libérés pour ne pas avoir le message d'erreur ci-dessus Ex.: $mysqli = new MySQLI('host','user','pass','db');<span class="Apple-tab-span" style="white-space:pre"> </span>// create a new instance of mysqli $query = $mysqli->real_query("CALL sp_somestoredproc()"); // automatically buffers resultsets and assigns true or false on fail to $query if ($query) { //check if the query was successful $result = $mysqli->use_result(); //asign the first result set for use $data = $result->fetch_assoc(); //use the data in the resultset $result->free(); //free the resultset while ($mysqli->next_result()) { //clear the other result(s) from buffer ; loop through each result using the next_result() method $result = $mysqli->use_result(); //free each result. if ($result instanceof mysqli_result) { <span class="Apple-tab-span" style="white-space:pre"> </span> $result->free(); <span class="Apple-tab-span" style="white-space:pre"> </span> } } $result2 = $mysqli->query("SELECT category_name FROM categories WHERE category_id = {$mysqli->escape_string($data['category_id'])}"); // use data from the first result to get other results ; granted this is not the best way, but well, lets just do it for example's sake. } |