note 88562 modified in mysqli.multi-query by thiago

From: Date: Thu, 29 Jan 2009 11:29:17 +0000
Subject: note 88562 modified in mysqli.multi-query by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-149942@lists.php.net to get a copy of this message
This is my point of view: Actually when calling $mysqli->next_result(), MySQL server will try to prepare resources for storing resultset. If you want to multi query for stored procedures, it's better to use $mysqli->use_result()->close() to close the resources. For functions, it's better to use $mysqli->store_result()->free() since there's resultset returned. Otherwise, an error of "Commands out of sync" will be rasied. Here's the code I test: <?php $mysql = new mysql('localhost', 'user', 'pw', 'db'); $query = 'show tables;'; $query.= 'show tables;'; $query.= 'select * from dummy_table;'; $query.= 'show tables;'; // this statement will be ignored as the dummy_table doesn't exist and the loop should quit $mysqli->multi_query($query); do { $mysqli->use_result()->close(); echo "Okay\n"; } while ($mysqli->next_result()); if ($mysqli->errno) { echo "Stopped while retrieving result : ".$mysqli->error; } ?> Returns : Okay Okay Stopped while retrieving result : Table 'db.dummy_table' doesn't exist --was-- This is my point of view: Actually when calling $mysqli->next_result(), MySQL server will try to prepare resources for storing resultset. If you want to multi query for stored procedures, it's better to use $mysqli->use_result()->close() to close the resources. For functions, it's better to use $mysqli->store_result()->free() since there's resultset returned. Otherwise, an error of "Commands out of sync" will be rasied. Here's the code I test: $mysql = new mysql('localhost', 'user', 'pw', 'db'); $query = 'show tables;'; $query.= 'show tables;'; $query.= 'select * from dummy_table;'; $query.= 'show tables;'; // this statement will be ignored as the dummy_table doesn't exist and the loop should quit $mysqli->multi_query($query); do { $mysqli->use_result()->close(); echo "Okay\n"; } while ($mysqli->next_result()); if ($mysqli->errno) { echo "Stopped while retrieving result : ".$mysqli->error; } Returns : Okay Okay Stopped while retrieving result : Table 'db.dummy_table' doesn't exist http://php.net/manual/en/mysqli.multi-query.php

« previous php.notes (#149942) next »