Jump to content
Larry Ullman's Book Forums

Prepared Statements, Mysqli_Stmt_Store_Result($Stmt);


Recommended Posts

On the presentation of prepared statements I've noticed an issue (at least on my machine):

 

I prepare the statement, I bind the parameters, I execute the query, than I check for a match:

 

$stmt = mysqli_prepare($dbc, $q);

mysqli_stmt_bind_param($stmt, 's', $name);

mysqli_stmt_execute($stmt);

if (mysqli_stmt_num_rows($stmt) == 1) {

echo "we have a match";

}

 

This does not produce the expected result. However, it will work if I add after I execute the query:

 

mysqli_stmt_store_result($stmt);

 

Is this an issue with my machine or something overlooked at the time of writting the book?

 

Thank you,

Greg

Link to comment
Share on other sites

  • 2 weeks later...

I am using inbound. I am running PHP Version 5.3.5 as an installation of XAMPP for Windows version 1.7.4. + Apache 2.2.17 + MySQL 5.5.8 (Community Server).

 

...

$name = "Ford";

$q = "SELECT id_tst, name_tst, price_tst FROM test_tst WHERE name_tst=?";

$stmt = mysqli_prepare($dbc, $q);

mysqli_stmt_bind_param($stmt, 's', $name);

mysqli_stmt_execute($stmt);

 

mysqli_stmt_store_result($stmt);

 

if (mysqli_stmt_num_rows($stmt) == 1) {

echo "we have a match";

}

 

mysqli_stmt_free_result($stmt);

mysqli_stmt_close($stmt);

mysqli_close($dbc);

...

 

On my machine, as reported, if I comment out mysqli_stmt_store_result($stmt) the example will fail to print "we have a match".

 

 

Thank you.

Link to comment
Share on other sites

 Share

×
×
  • Create New...