PHP mysqli_ping()Function
Detect server connection:
<?php
// 假定数据库用户名:root,密码:123456,数据库:EXAMPLE
$con=mysqli_connect("localhost","root","123456","EXAMPLE");
if (mysqli_connect_errno($con))
{
echo "连接 MySQL 失败: " . mysqli_connect_error();
}
// 检测 MySQL 服务器是否可用
if (mysqli_ping($con))
{
echo "连接正常!";
}
else
{
echo "错误: ". mysqli_error($con);
}
mysqli_close($con);
?>
Definition and Usage
The mysqli_ping() function performs a server connection, and attempts to reconnect if the connection has been lost.
Syntax
mysqli_ping(connection);
| Parameters | Description |
|---|---|
| connection | Required. Specifies the MySQL connection to use. |
Technical Details
| Return value: | Returns TRUE on success, or FALSE on failure. |
|---|---|
| PHP Version: | 5+ |
PHP MySQLi Reference Manual Other Extensions