SamohtVII Posted July 25, 2014 Share Posted July 25, 2014 So I just converted my mysql to mysqli and I noticed when I do something like this: $sql = $mysqli->query("SELECT * FROM `history` WHERE user = '$user'"); while($row = $sql->fetch_assoc()) { //DO SOMETHING } ?> If the query finds nothing it gets an error so now I am prefixing all my while statements with if($sql). If mysqli is so much better why does this error happen and is there a better way for me to avoid adding that extra if everytime. Thanks Link to comment Share on other sites More sharing options...
niche Posted July 25, 2014 Share Posted July 25, 2014 (edited) What's the error? BTW, don't think you need the table name in quotes. Also, use mysqli_error www.w3schools.com/php/func_mysqli_error.asp Edited July 25, 2014 by niche Link to comment Share on other sites More sharing options...
justsomeguy Posted July 25, 2014 Share Posted July 25, 2014 If mysqli is so much better why does this error happenThe mysqli extension will not automatically make you a better programmer, sorry. Just because you didn't bother to do any error checking when you were using the mysql extension doesn't mean that you should go forward and blindly assume that things are working without bothering to check. Look in the documentation for information about checking for errors in queries, checking how many records were returned, etc. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now