note 88562 added to mysqli.multi-query
| From: | raye1010 at yahoo dot com dot hk | Date: | Thu, 29 Jan 2009 06:56:20 +0000 |
| Subject: | note 88562 added to mysqli.multi-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-149931@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:
$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
----
Server IP: 203.169.164.89
Probable Submitter: 210.3.51.98
----
Manual Page -- http://www.php.net/manual/en/mysqli.multi-query.php
Edit -- https://master.php.net/note/edit/88562
Del: integrated -- https://master.php.net/note/delete/88562/integrated
Del: useless -- https://master.php.net/note/delete/88562/useless
Del: bad code -- https://master.php.net/note/delete/88562/bad+code
Del: spam -- https://master.php.net/note/delete/88562/spam
Del: non-english -- https://master.php.net/note/delete/88562/non-english
Del: in docs -- https://master.php.net/note/delete/88562/in+docs
Del: other reasons-- https://master.php.net/note/delete/88562
Reject -- https://master.php.net/note/reject/88562
Search -- https://master.php.net/manage/user-notes.php