HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
PHP MySQLi Reference : Ping a server connection
The ping() / mysqli_ping() function pings a server connection, to check if the server is alive. It also tries to reconnect - if the connection has gone down.
Object oriented style:
Procedural style:
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to use |
Return Value: | TRUE on success. FALSE on failure |
---|---|
PHP Version: | 5+ |
Ping a server connection:
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
// Check if server is alive
if (mysqli_ping($con)) {
echo "Connection is ok!";
} else {
echo "Error: ". mysqli_error($con);
}
mysqli_close($con);
?>
❮ PHP MySQLi Reference