glassfish Posted October 7, 2014 Share Posted October 7, 2014 Is there an alert method for the MySQL database or something similar? What is the proper way to check if the MySQL database connection is working? I mean other than "creating" and "retrieving" with "insert" and "select". Quote Link to comment https://forums.phpfreaks.com/topic/291489-checking-if-the-mysql-database-connection-is-working/ Share on other sites More sharing options...
Ch0cu3r Posted October 7, 2014 Share Posted October 7, 2014 (edited) Why not look at the relevant documentation? It explains what each connection method returns and code examples of how to connect and test if the connection works. mysql mysqli pdo Edited October 7, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/291489-checking-if-the-mysql-database-connection-is-working/#findComment-1492955 Share on other sites More sharing options...
glassfish Posted October 7, 2014 Author Share Posted October 7, 2014 (edited) <?php $dbc = mysqli_connect('localhost', 'root', '', 'testing'); if(!$dbc){ die('Connect Error ('. mysqli_connect_errno() . ') ' . mysqli_connect_error()); } echo "Success..." . mysqli_get_host_info($dbc) . "\n"; mysqli_close($dbc); ?> Success...localhost via TCP/IP When is it set? What is the return value? Edited October 7, 2014 by glassfish Quote Link to comment https://forums.phpfreaks.com/topic/291489-checking-if-the-mysql-database-connection-is-working/#findComment-1492959 Share on other sites More sharing options...
jcbones Posted October 9, 2014 Share Posted October 9, 2014 (edited) Well, from your example, the mysqli_get_host_info($dbc) returned 'localhost via TCP/IP', but specifically according to documentationManual says Return Values ¶ A character string representing the server hostname and the connection type. Otherwise your example shows the connection to the database through mysqli, and IF IT FAILS the script dies (exits, quits) while outputting the the returned values of mysqli_connect_errno() and mysqli_connect_error(). Which are sequentially:mysql_connect_errno() Return Values ¶ An error code value for the last call to mysqli_connect(), if it failed. zero means no error occurred. mysql_connect_error() Return Values ¶ A string that describes the error. NULL is returned if no error occurred. Edited October 9, 2014 by jcbones Quote Link to comment https://forums.phpfreaks.com/topic/291489-checking-if-the-mysql-database-connection-is-working/#findComment-1493090 Share on other sites More sharing options...
glassfish Posted October 9, 2014 Author Share Posted October 9, 2014 Thanks for clarifying. Quote Link to comment https://forums.phpfreaks.com/topic/291489-checking-if-the-mysql-database-connection-is-working/#findComment-1493176 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.