note 75534 modified in function.mysqli-stmt-prepare by danbrown

From: Date: Fri, 28 Nov 2008 22:49:45 +0000
Subject: note 75534 modified in function.mysqli-stmt-prepare by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147386@lists.php.net to get a copy of this message
In reference to what lachlan76 said before, stored procedures CAN be executed through prepared statements as long as you tell the DB to move to the next result before executing again. Example (Five calls to a stored procedure): <?php for ($i=0;$i<5;$i++) { $statement = $mysqli->stmt_init(); $statement->prepare("CALL some_procedure( ? )"); // Bind, execute, and bind. $statement->bind_param("i", 1); $statement->execute(); $statement->bind_result($results); while($statement->fetch()) { // Do what you want with your results. } $statement->close(); // Now move the mysqli connection to a new result. while($mysqli->next_result()) { } } ?> If you include the last statement, this code should execute without the nasty "Commands out of sync" error. --was-- In reference to what lachlan76 said before, stored procedures CAN be executed through prepared statements as long as you tell the DB to move to the next result before executing again. Example (Five calls to a stored procedure): <?php for ($i=0;$i<5;$i++) { $statement = $mysqli->stmt_init(); $statement->prepare("CALL some_procedure( ? )"); // Bind, execute, and bind. $statement->bind_param("i", 1); $statement->execute(); $statement->bind_result($results); while($statement->fetch()) { // Do what you want with your results. } $statement->close(); // Now move the mysqli connection to a new result. while($mysqli->next_result()) { } } ?> If you include the last statement, this code should execute without the nasty "Commands out of sync" error. http://php.net/manual/en/function.mysqli-stmt-prepare.php

« previous php.notes (#147386) next »