Easy Tutorial
❮ Func String Strtok Func Filesystem Fgetc ❯

PHP mysqli_ping() Function

PHP MySQLi Reference Manual

Check Server Connection:

<?php 
// Assume database username: root, password: 123456, database: tutorialpro 
$con = mysqli_connect("localhost", "root", "123456", "tutorialpro"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 

// Check if the MySQL server is reachable
if (mysqli_ping($con))
{
    echo "Connection is OK!";
}
else
{
    echo "Error: " . mysqli_error($con);
}

mysqli_close($con);
?>

Definition and Usage

The mysqli_ping() function pings a server connection, or tries to reconnect if the connection has gone down.


Syntax

Parameter Description
connection Required. Specifies the MySQL connection to use.

Technical Details

Return Value: Returns TRUE on success, FALSE on failure.
PHP Version: 5+
--- ---
❮ Func String Strtok Func Filesystem Fgetc ❯