I have the following PHP code:
$con = mysql_connect("localhost","name","pass") or die(mysql_error());
$db = "db";
mysql_select_db($db,$con);
Now in my experience, $con should be true or false. When I echo $con I get:
Resource id #25
If I do the following code, the echo never fires (as to be expected after the above statement):
if($con) { echo "it worked"; }
When I run a query against this connection, everything works as expected. Is there a reason why this $con will not be true or false?
What am I doing wrong?
Thanks
Check
mysql_connectReturn Values :So to check the connection:
or to quit in case of an error:
A word of advice though, better to use the MySQLi or PDO_MySQL instead of
mysql_connectsince it will soon be deprecated: