note 112778 added to mysqli.multi-query
| From: | LubaevK | Date: | Mon, 22 Jul 2013 09:15:43 +0000 |
| Subject: | note 112778 added to mysqli.multi-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195713@lists.php.net to get a copy of this message | ||
Use generator.
PHP 5.5.0
<?php
// Quick multiQuery func.
function multiQuery( mysqli $mysqli, $query ) {
if ($mysqli->multi_query( $query )) {
do {
if ($result = $mysqli->store_result()) {
while ($row = $result->fetch_row()) {
foreach ($row as $key => $value) yield $key => $value;
}
$result->free();
}
} while( $mysqli->more_results() && $mysqli->next_result() );
}
}
$query = "OPTIMIZE TABLE
question;" .
"LOCK TABLES question READ;" .
"SELECT * FROM question WHERE questionid=2;" .
"SELECT * FROM question WHERE questionid=7;" .
"SELECT * FROM question WHERE questionid=8;" .
"SELECT * FROM question WHERE questionid=9;" .
"SELECT * FROM question WHERE questionid=11;" .
"SELECT * FROM question WHERE questionid=12;" .
"UNLOCK TABLES;" .
"TRUNCATE TABLE question;";
$mysqli = new mysqli('localhost', 'user', 'pswd', 'dbnm');
$mysqli->set_charset("cp1251");
// result
foreach ( multiQuery($mysqli, $query) as $key => $value ) {
echo $key, $value, PHP_EOL;
}
?>
Good luck!
----
Server IP: 69.147.83.199
Probable Submitter: 95.161.27.39
----
Manual Page -- http://php.net/manual/en/mysqli.multi-query.php
Edit -- https://master.php.net/note/edit/112778
Del: integrated -- https://master.php.net/note/delete/112778/integrated
Del: useless -- https://master.php.net/note/delete/112778/useless
Del: bad code -- https://master.php.net/note/delete/112778/bad+code
Del: spam -- https://master.php.net/note/delete/112778/spam
Del: non-english -- https://master.php.net/note/delete/112778/non-english
Del: in docs -- https://master.php.net/note/delete/112778/in+docs
Del: other reasons-- https://master.php.net/note/delete/112778
Reject -- https://master.php.net/note/reject/112778
Search -- https://master.php.net/manage/user-notes.php