mysqli_ping,
mysqli_ping, mysqli->ping() — サーバとの接続をチェックし、もし切断されている場合は再接続を試みる
説明
手続き型:bool mysqli_ping ( mysqli link )
オブジェクト指向型(メソッド):
class mysqli {
bool ping ( void )
} サーバとの接続が動作中かどうかを確かめます。もし切断されており、 グローバルオプション mysqli.reconnect が有効な場合は 再接続が試みられます。
この関数は、長期間アイドル状態にあるクライアントが、 サーバの状態を確認して必要なら再接続するために使用します。
パラメータ
- link
- 手続き型のみ:
mysqli_connect() あるいは mysqli_init() が返すリンク ID。
返り値
成功した場合に TRUE を、失敗した場合に FALSE を返します。例
例 1430. オブジェクト指向型
<?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();
?>
例 1431. 手続き型
<?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);
?>
上の例の出力は以下となります。
Our connection is ok!
Weblioに収録されているすべての辞書からmysqli_ping,を検索する場合は、下記のリンクをクリックしてください。

- mysqli_ping,のページへのリンク