mysqli::ping
(PHP 5, PHP 7, PHP 8)
mysqli::ping -- mysqli_ping — 서버 연결을 핑하거나 연결이 끊긴 경우 다시 연결을 시도합니다.
설명
객체 지향 스타일
public mysqli::ping(): bool
절차적 스타일
mysqli_ping(mysqli $mysql
): bool
서버에 대한 연결이 작동하는지 확인합니다. 다운되고 전역 옵션 mysqli.reconnect가 활성화되면 자동 재연결이 시도됩니다.
참고: php.ini 설정 mysqli.reconnect는 mysqlnd 드라이버에서 무시되므로 자동 재연결이 시도되지 않습니다.
이 함수는 오랫동안 유휴 상태를 유지하는 클라이언트에서 서버가 연결을 닫았는지 확인하고 필요한 경우 다시 연결하는 데 사용할 수 있습니다.
매개변수
mysql
- 절차적 스타일 전용: mysqli_connect() 또는 mysqli_init()에 의해 반환된 mysqli 객체
반환 값
성공하면 true
를, 실패하면 false
를 반환합니다.
Examples
예제 #1 mysqli::ping() 예제
객체 지향 스타일
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
/* check if server is alive */
if ($mysqli->ping()) {
printf ("Our connection is ok!\n");
} else {
printf ("Error: %s\n", $mysqli->error);
}
/* close connection */
$mysqli->close();
?>
절차적 스타일
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* check if server is alive */
if (mysqli_ping($link)) {
printf ("Our connection is ok!\n");
} else {
printf ("Error: %s\n", mysqli_error($link));
}
/* close connection */
mysqli_close($link);
?>
위의 예는 다음을 출력합니다.
Our connection is ok!