PHP mysqli_ping () function
Detection server connection:
<?php // 假定数据库用户名:root,密码:123456,数据库:w3big $con=mysqli_connect("localhost","root","123456","w3big"); 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
mysqli_ping () function a server connection, if the connection has been broken it attempts to reconnect.
grammar
mysqli_ping( connection ) ;
参数 | 描述 |
---|---|
connection | 必需。规定要使用的 MySQL 连接。 |
technical details
return value: | If successful it returns TRUE, on failure returns FALSE. |
---|---|
PHP version: | 5+ |
PHP MySQLi Reference Manual