mysqli::ping
mysqli_ping
(PHP 5)
mysqli_ping — Pings a server connection, or tries to reconnect if the connection has gone down
Description
Object oriented style (method):
bool mysqli::ping
( void
)
bool mysqli_ping
(
mysqli $link
)
This function can be used by clients that remain idle for a long while,
to check whether the server has closed the connection and reconnect if
necessary.
Return Values
Returns TRUE on success or FALSE on failure.
Examples
Example #1 Object oriented style
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if ($mysqli->ping()) {
printf ("Our connection is ok!\n");
} else {
printf ("Error: %s\n", $mysqli->error);
}
$mysqli->close();
?>
Example #2 Procedural style
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if (mysqli_ping($link)) {
printf ("Our connection is ok!\n");
} else {
printf ("Error: %s\n", mysqli_error($link));
}
mysqli_close($link);
?>
The above example will output: