mysqli_stmt::store_result? [message #174224] |
Fri, 27 May 2011 16:20 |
David
Messages: 2 Registered: December 2010
Karma: 0
|
Junior Member |
|
|
Hmm.. My attempt to run two mysqli prepared statements (SELECT queries), one
immediately after the other, failed with the error:
"mysqli::prepare() [function.mysqli-prepare]: All data must be fetched
before a new statement prepare takes place"
Searching for clues about this error message eventually led me to
mysqli_stmt::store_result, but what does this function actually *do*?
(The description in the manual is somewhat terse to say the least..)
http://www.php.net/manual/en/mysqli-stmt.store-result.php
I'd been using "ext/mysqli: Part I - Overview and Prepared Statements" as my
guide to using prepared statements, and mysqli_stmt::store_result doesn't
seem to feature in the examples there at all? (!)
http://devzone.zend.com/article/686
My code was along the lines of:
// $dbh is my DB handle..
$stmt = $dbh->prepare("
SELECT
some data..
WHERE
some conditions.. = ?
");
$stmt->bind_param('i..', some values from variables..);
$stmt->execute();
$stmt->bind_result(
some variables corresponding to the selected data..
);
$stmt2 = $dbh->prepare("
etc...
At this point I now wanted to 'prepare' my next query ($stmt2) so that I'd
have all of the data I needed, and could then (I thought) worry about
actually fetching the data from these result sets, and processing that data,
at a later point in my code.
But not so, obviously my understanding is wrong..
So, at which point in the sequence of commands does the result set actually
get extracted from the database for PHP to deal with? I had assumed that
that was what 'execute' did: then (somewhat at your leisure) 'bind_result'
matched up the field names in the result set with your desired variable
names, and then finally 'fetch' grabbed the next row from the result set..?
But it's looking as though 'store_result' may be what actually produces the
result set? But this command was missing from the tutorial on the Zend
website, and my previous code had been working fine without it.. I'm
thoroughly confused!
If anybody can offer any advice to aid my understanding, I'd be very grateful!
Thanks,
David.
|
|
|
Re: mysqli_stmt::store_result? [message #174225 is a reply to message #174224] |
Fri, 27 May 2011 17:19 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 5/27/2011 12:20 PM, David wrote:
>
> Hmm.. My attempt to run two mysqli prepared statements (SELECT queries),
> one
> immediately after the other, failed with the error:
>
> "mysqli::prepare() [function.mysqli-prepare]: All data must be fetched
> before a new statement prepare takes place"
>
>
> Searching for clues about this error message eventually led me to
> mysqli_stmt::store_result, but what does this function actually *do*?
> (The description in the manual is somewhat terse to say the least..)
>
> http://www.php.net/manual/en/mysqli-stmt.store-result.php
>
>
> I'd been using "ext/mysqli: Part I - Overview and Prepared Statements"
> as my
> guide to using prepared statements, and mysqli_stmt::store_result doesn't
> seem to feature in the examples there at all? (!)
>
> http://devzone.zend.com/article/686
>
>
> My code was along the lines of:
>
> // $dbh is my DB handle..
> $stmt = $dbh->prepare("
> SELECT
> some data..
> WHERE
> some conditions.. = ?
> ");
>
> $stmt->bind_param('i..', some values from variables..);
>
> $stmt->execute();
>
> $stmt->bind_result(
> some variables corresponding to the selected data..
> );
>
>
> $stmt2 = $dbh->prepare("
> etc...
>
> At this point I now wanted to 'prepare' my next query ($stmt2) so that
> I'd have all of the data I needed, and could then (I thought) worry
> about actually fetching the data from these result sets, and processing
> that data, at a later point in my code.
>
> But not so, obviously my understanding is wrong..
>
> So, at which point in the sequence of commands does the result set
> actually get extracted from the database for PHP to deal with? I had
> assumed that that was what 'execute' did: then (somewhat at your
> leisure) 'bind_result' matched up the field names in the result set with
> your desired variable names, and then finally 'fetch' grabbed the next
> row from the result set..?
>
> But it's looking as though 'store_result' may be what actually produces
> the result set? But this command was missing from the tutorial on the
> Zend website, and my previous code had been working fine without it..
> I'm thoroughly confused!
>
> If anybody can offer any advice to aid my understanding, I'd be very
> grateful!
>
> Thanks,
>
>
> David.
>
The mysql_xxx() functions are just wrappers for the equivalent MySQL C
language functions. Usually you get better doc for these functions in
the MySQL manual.
In this case see
http://dev.mysql.com/doc/refman/5.5/en/mysql-store-result.html.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|