masterlayouts Posted January 28, 2012 Share Posted January 28, 2012 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 More sharing options...
Larry Posted January 30, 2012 Share Posted January 30, 2012 It really depends upon the type of query being run. And are you using inbound or outbound parameters? It'd help to know the versions involved, too. Link to comment Share on other sites More sharing options...
masterlayouts Posted February 11, 2012 Author Share Posted February 11, 2012 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 More sharing options...
Jonathon Posted February 11, 2012 Share Posted February 11, 2012 You need to store the result for outbound queries, you do not need this step for inbound ones, you would more likely just use if(mysqli_stmt_affected_rows($stmt) ==1){} to confirm that 1 row was affected. 1 Link to comment Share on other sites More sharing options...
Recommended Posts