Jump to content

Checking If the MySQL Database Connection is Working?


glassfish

Recommended Posts

 

<?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?

Well, from your example, the mysqli_get_host_info($dbc) returned 'localhost via TCP/IP', but specifically according to documentation

Manual 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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.