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


Groups > comp.lang.php > #1879

mysqli_stmt::store_result?

From David <david@55952163-3189045.bogus.domain.invalid>
Newsgroups comp.lang.php
Subject mysqli_stmt::store_result?
Date 2011-05-27 17:20 +0100
Organization A noiseless patient Spider
Message-ID <iroivn$5st$1@dont-email.me> (permalink)

Show all headers | View raw


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.

Back to comp.lang.php | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

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

csiph-web