note 119819 added to mysqli.stmt-init
| From: | JeffC | Date: | Wed, 31 Aug 2016 21:32:05 +0000 |
| Subject: | note 119819 added to mysqli.stmt-init | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206447@lists.php.net to get a copy of this message | ||
stmt_init() seems to clear previous (possibly erroneous) results on the DB connection, which means
you don't necessarily need to use it but it could make the code more robust.
In a PHPUnit test, I had a sequence of prepared queries on the same connection. One of them fetched
a row from a SELECT but didn't keep fetching until it drained the connection, so it left some
stale results. When the next query did this:
<?php
$db = $this->getConnection()->getDbConnection();
$preparedQuery = $db->prepare ($query);
?>
the prepare() call generated an error: "Could not prepare query: Commands out of sync; you
can't run this command now." Changing to this:
<?php
$db = $this->getConnection()->getDbConnection();
$preparedQuery = $db->stmt_init();
$preparedQuery->prepare ($query);
?>
resolved the problem.
----
Server IP: 72.52.91.14
Probable Submitter: 184.178.219.82
----
Manual Page -- http://php.net/manual/en/mysqli.stmt-init.php
Edit -- https://master.php.net/note/edit/119819
Del: integrated -- https://master.php.net/note/delete/119819/integrated
Del: useless -- https://master.php.net/note/delete/119819/useless
Del: bad code -- https://master.php.net/note/delete/119819/bad+code
Del: spam -- https://master.php.net/note/delete/119819/spam
Del: non-english -- https://master.php.net/note/delete/119819/non-english
Del: in docs -- https://master.php.net/note/delete/119819/in+docs
Del: other reasons-- https://master.php.net/note/delete/119819
Reject -- https://master.php.net/note/reject/119819
Search -- https://master.php.net/manage/user-notes.php