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?

Edited by glassfish
Link to comment
Share on other sites

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.

 

Edited by jcbones
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.