eduard Posted February 10, 2011 Share Posted February 10, 2011 How do I know my php file is connected to MySQL? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 10, 2011 Share Posted February 10, 2011 If the mysql_connect function returns false, it did not connect. If it does not return false then it did connect. Link to comment Share on other sites More sharing options...
boen_robot Posted February 10, 2011 Share Posted February 10, 2011 See examples in the tutorial. As the paragraph above the first example says, if the connection fails, the "die" part will execute. Logically, if it's NOT executed, you can assume PHP is connected to MySQL. Link to comment Share on other sites More sharing options...
eduard Posted February 10, 2011 Author Share Posted February 10, 2011 If the mysql_connect function returns false, it did not connect. If it does not return false then it did connect.Thanks! Link to comment Share on other sites More sharing options...
eduard Posted February 10, 2011 Author Share Posted February 10, 2011 See examples in the tutorial. As the paragraph above the first example says, if the connection fails, the "die" part will execute. Logically, if it's NOT executed, you can assume PHP is connected to MySQL.Thanks, however I don´t like the verb: ´assume´! I want to be sure! Link to comment Share on other sites More sharing options...
boen_robot Posted February 16, 2011 Share Posted February 16, 2011 Let me paraphrase that... you can SAFELY assume PHP is connected to MySQL... if you don't see the error message.mysql_connect() can return only two things - the boolean value false (in which case the connection failed) and a MySQL resource (in which the connection was successful).The examples on W3Schools test if the value is false, and if it is, they show the error message. Because the only other option is known to be a MySQL resource, it is SAFE to assume that if the value is not false, the connection is successful.The assumption would not be safe if there was a third thing that mysql_connect() could return, but in this case, there isn't. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.