note 65810 added to function.mysqli-multi-query
| From: | info at ff dot net | Date: | Mon, 08 May 2006 11:02:30 +0000 |
| Subject: | note 65810 added to function.mysqli-multi-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-110846@lists.php.net to get a copy of this message | ||
Note that you need to use this function to call Stored Procedures!
If you experience "lost connection to MySQL server" errors with your Stored Procedure
calls then you did not fetch the 'OK' (or 'ERR') message, which is a second
result-set from a Stored Procedure call. You have to fetch that result to have no problems with
subsequent queries.
Bad example, will FAIL now and then on subsequent calls:
<?php
$sQuery='CALL exampleSP('param')';
if(!mysqli_multi_query($this->sqlLink,$sQuery))
$this->queryError();
$this->sqlResult=mysqli_store_result($this->sqlLink);
?>
Working example:
<?php
$sQuery='CALL exampleSP('param')';
if(!mysqli_multi_query($this->sqlLink,$sQuery))
$this->queryError();
$this->sqlResult=mysqli_store_result($this->sqlLink);
if(mysqli_more_results($this->sqlLink))
while(mysqli_next_result($this->sqlLink));
?>
Of course you can do more with the multiple results then just throwing them away, but for most this
will suffice. You could for example make an "sp" function which will kill the 2nd
'ok' result.
This nasty 'OK'-message made me spend hours trying to figure out why MySQL server was
logging warnings with 'bad packets from client' and PHP mysql_error() with
'Connection lost'. It's a shame the mysqli library does catch this by just doing it
for you.
----
Server IP: 83.137.20.120
Probable Submitter: 86.85.230.21
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.mysqli-multi-query.php
Edit -- http://master.php.net/note/edit/65810
Del: integrated -- http://master.php.net/note/delete/65810/integrated
Del: useless -- http://master.php.net/note/delete/65810/useless
Del: bad code -- http://master.php.net/note/delete/65810/bad+code
Del: spam -- http://master.php.net/note/delete/65810/spam
Del: non-english -- http://master.php.net/note/delete/65810/non-english
Del: in docs -- http://master.php.net/note/delete/65810/in+docs
Del: other reasons-- http://master.php.net/note/delete/65810
Reject -- http://master.php.net/note/reject/65810
Search -- http://master.php.net/manage/user-notes.php