Yes, I have tried the mysqli_stmt_get_result function and it works, but do you know how I can combine this with
mysqli_stmt_num_rows http://php.net/manual/en/mysqli-stmt.num-rows.php or something similar? I need to find the number of rows returned before I use mysqli_fetch_array.
Hi, I tried this and receive an error message, mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given. Perhaps one must use another technique to fetch the data after having stored it? Came across this sitepoint post where mysqli_stmt_bind_result is used. Don’t know if I should use that.
OK, so if $result is a boolean value rather than an instance of mysqli_result, that means mysqli_stmt_get_result is not returning what we expect - if you check the manual page for this function, it says:
Returns a resultset or FALSE on failure.
So there’s a problem with your statement somewhere.
Hi, as far as I know both fare equally well in preventing SQL injection, but for performance mysqli seems faster. Everyone has a different opinion, I’ll just be glad if I manage to get either of these working
Hi, as far as I know both fare equally well in preventing SQL injection, but for performance mysqli seems faster.
It is faster since PDO merely wraps around mysqli, but if the very slight different between the two is critical to you then you’re using the wrong programming language to begin with. I personally don’t consider the lack of code portability to be worth it.
Well i dont think it makes sense from a situation standpoint - if the number of rows is any-number-greater-than-0, you’d need to loop through them. And at that point, a while($row = mysqli_fetch_array… gets you the same result, without having to look up the number of rows.
If we’re talking about a single-row result set (So you’d be checking for num_rows == 1), then it makes more sense.
Thanks StarLion, I see what you mean, but regardless of the situation do you think the code is OK how it is written - mixing the procedural with the oop? I had a problem using mysqli_stmt_store_result with mysqli_stmt_num_rows, which is why I tried $result → num_rows. Would you say that this is an appropriate way of checking the row count after having used mysqli_stmt_get_result?