Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #1879 > unrolled thread

mysqli_stmt::store_result?

Started byDavid <david@55952163-3189045.bogus.domain.invalid>
First post2011-05-27 17:20 +0100
Last post2011-05-27 13:19 -0400
Articles 2 — 2 participants

Back to article view | Back to comp.lang.php


Contents

  mysqli_stmt::store_result? David <david@55952163-3189045.bogus.domain.invalid> - 2011-05-27 17:20 +0100
    Re: mysqli_stmt::store_result? Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-27 13:19 -0400

#1879 — mysqli_stmt::store_result?

FromDavid <david@55952163-3189045.bogus.domain.invalid>
Date2011-05-27 17:20 +0100
Subjectmysqli_stmt::store_result?
Message-ID<iroivn$5st$1@dont-email.me>
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.

[toc] | [next] | [standalone]


#1880

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-05-27 13:19 -0400
Message-ID<iromg2$ue6$1@dont-email.me>
In reply to#1879
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@attglobal.net
==================

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web