Re: Performing Multiple Prepared Queries
| From: | Carlton Whitehead | Date: | Wed, 03 Oct 2007 17:07:25 +0000 |
| Subject: | Re: Performing Multiple Prepared Queries | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-262696@lists.php.net to get a copy of this message | ||
Hi Nathaniel,
When your query starts its second loop, the resultset from the first one is still defined as the
resultset in your prepared statement object. Before you can get another resultset, you need to
clear the first one using the mysqli_stmt_free_result function. It would probably be best to place
the free_result call after each call to fetch. Check http://www.php.net/manual/en/function.mysqli-free-result.php
for more details about it.
Regards,
Carlton Whitehead
----- Original Message -----
From: "Nathaniel Hall" <lists@spider-security.net>
To: php-general@lists.php.net
Sent: Wednesday, October 3, 2007 10:47:22 AM (GMT-0500) America/New_York
Subject: [PHP] Performing Multiple Prepared Queries
All,
I am attempting to perform multiple prepared queries using mysqli. I
want to pull information out of one table based on the information in
another. I do not receive any errors and the rest of the page seems to
load correctly. Below is my code:
foreach ($uniqueids as $entryid) {
$getentrybyid->bind_param("i", $entryid);
$getentrybyid->execute();
$getentrybyid->bind_result($level, $published, $updated, $title, $body,
$resources, $signature, $comments);
$getentrybyid->fetch();
$getentrybyid->close();
$getsignaturebyid->bind_param("i", $signature);
$getsignaturebyid->execute();
$getsignaturebyid->bind_result($fname, $lname);
$getsignaturebyid->fetch();
$getsignaturebyid->close();
printEntry($title, $level, $published, $updated, "$fname $lname",
$body, $resources);
if ($comments == 'y') {
echo "<div class=\"viewcomment\"><a
href=\"$http_path?entryid=$entryid\">View Comments...</a></div>\n";
}
}
What ends up happening is the first query (getentrybyid) works just fine
and displays when told. The second query (getsignaturebyid) does not
get the information that it is supposed to, thus the variable is empty.
NOTE: I have moved the close() functions outside of the foreach loop
and it partially works. It starts displaying the information it is
supposed ($fname $lname) but it repeats the rest of the information.
Any thoughts?
--
Nathaniel Hall, GSEC GCFW GCIA GCIH GCFA
Spider Security
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php