Re: Performing Multiple Prepared Queries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxxx>
To: php-general@xxxxxxxxxxxxx
Sent: Wednesday, October 3, 2007 10:47:22 AM (GMT-0500) America/New_York
Subject:  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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux