ala888 Posted July 14, 2014 Share Posted July 14, 2014 I've seen some individuals use the following method to validate whether or not an attempted connection to mySQL went through. $CON = mysqli_connect("localhost","root","123456","test")if($CON){......} First of all, I dont understand how an object evaluates to a boolean true. And secondly, how come mysqli_connect returns absolutely nothing when it does not work? Link to comment Share on other sites More sharing options...
niche Posted July 14, 2014 Share Posted July 14, 2014 (edited) see http://www.w3schools.com/php/func_mysqli_connect.asp (doesn't use $CON in the example). and http://www.w3schools.com/php/func_mysqli_error.asp Edited July 14, 2014 by niche Link to comment Share on other sites More sharing options...
ala888 Posted July 14, 2014 Author Share Posted July 14, 2014 I tried substituting mysqli_connect_errno with mysqli_errno to no avail. Any Idea why it doesnt work? Is there some fundamental divide between error logging between connect functions and the rest? Link to comment Share on other sites More sharing options...
niche Posted July 14, 2014 Share Posted July 14, 2014 What error message are you getting? Link to comment Share on other sites More sharing options...
thescientist Posted July 14, 2014 Share Posted July 14, 2014 what's the error message, and what does the code look like now? Link to comment Share on other sites More sharing options...
ala888 Posted July 14, 2014 Author Share Posted July 14, 2014 absolutely no error message, it doesn't return anything at all. only the php warning ("failed to connect to mysql server") that actual function msqli_errno doesnt return anything Link to comment Share on other sites More sharing options...
Don Jajo Posted July 15, 2014 Share Posted July 15, 2014 (edited) try <?php$con = mysqli_connect(db_details) or die(mysqli_error($con));?> Edited July 15, 2014 by Don Jajo Link to comment Share on other sites More sharing options...
ala888 Posted July 15, 2014 Author Share Posted July 15, 2014 the die command works, except I want to do my own error handling and not terminate on the spot.mysqli_connect_errno is perfect. I just dont understand why mysqli_errno does not work. but its not a big deal Link to comment Share on other sites More sharing options...
thescientist Posted July 15, 2014 Share Posted July 15, 2014 as I said before, show your code. Link to comment Share on other sites More sharing options...
ala888 Posted July 17, 2014 Author Share Posted July 17, 2014 nvm, I figured it out. mysqli_errno checks for the last error in a specific connection to a database. If the connection itself did not exist due to failure, there would not be any errors Link to comment Share on other sites More sharing options...
justsomeguy Posted July 21, 2014 Share Posted July 21, 2014 This lists the values that will evaluate to boolean false. Everything else is considered true.http://php.net/manual/en/language.types.boolean.php 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