NYCPHP Meetup

NYPHP.org

[nycphp-talk] mysqli prepared statements

William Klein willie at pdfsystems.com
Thu Jan 4 16:38:46 EST 2007


Well I figured this out but I can't explain why it works.

This statement is in a while loop, which is why I was using prepared
statements to begin with.  I have another prepared statement which should
only have 1 record in the result, I'm searching on a unique primary key.
However when I do a $statement1->fetch() the second statement doesn't work.
When I put the first result into a while loop 
While($statement1->fetch()){
	Echo"showroom is $showroom<BR>";
}

The second statement executes fine.

Now would anyone know why this would be? 

________________________________________
From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org] On
Behalf Of willie klein
Sent: Thursday, January 04, 2007 11:28 AM
To: talk at lists.nyphp.org
Subject: [nycphp-talk] mysqli prepared statements

Hi All;

I just started using prepared statements.  So far I have been very impressed
by how much of a performance enhancement there is when using them.  I have a
query that isn’t working now though and I’m not sure how to troubleshoot
it.  I used to just echo out the query and I could see where the problem
was.  I keep getting an empty result set from a query I know should have
data in it.  Is there a way to see the prepared query as the server sees
it?  I keep echoing out mysqli_error($dbi) but there is nothing in it.  

Relevant Code:
$statement2 = $dbi->prepare("select  date, date_format(date ,' %b %d %y') as
dta from 1TrackUser where loginID = ? ORDER BY date");// if
(mysqli_error($dbi)) {
          echo "ERROR: ".mysqli_error($dbi)."<BR>"; } echo "ShowroomLoginID
= $ShowroomloginID<br>"; // something valid is here
$statement2->bind_param("s",$ShowroomloginID);        
$statement2->execute();
$statement2->bind_result($date,$dta);
$TotalLogin = $statement2->num_rows ; // always 0 when I run query manually
it works.

Thanks
Willie            






More information about the talk mailing list