FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » mysqli_stmt::store_result?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
mysqli_stmt::store_result? [message #174224] Fri, 27 May 2011 16:20 Go to next message
David is currently offline  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 Go to previous message
Jerry Stuckle is currently offline  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
==================
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: looking for ideas on how turn a php created html table with 10 rows into a 2 row table with extra columns appended to the end
Next Topic: Persistence engine for GWT
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 01 00:29:05 GMT 2024

Total time taken to generate the page: 0.02823 seconds