array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'uk', ), 'this' => array ( 0 => 'mysqli.ping.php', 1 => 'mysqli::ping', 2 => 'Pings a server connection, or tries to reconnect if the connection has gone down', ), 'up' => array ( 0 => 'class.mysqli.php', 1 => 'mysqli', ), 'prev' => array ( 0 => 'mysqli.options.php', 1 => 'mysqli::options', ), 'next' => array ( 0 => 'mysqli.poll.php', 1 => 'mysqli::poll', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/mysqli/mysqli/ping.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>
(PHP 5, PHP 7, PHP 8)
mysqli::ping -- mysqli_ping — Pings a server connection, or tries to reconnect if the connection has gone down
Ця функція ЗАСТАРІЛА, починаючи з PHP 8.4.0. Вкрай не рекомендується на неї покладатися.
Об'єктно-орієнтований стиль
Процедурний стиль
Checks whether the connection to the server is working. If it has gone down and global option mysqli.reconnect is enabled, an automatic reconnection is attempted.
Зауваження: The php.ini setting mysqli.reconnect is ignored by the mysqlnd driver, so automatic reconnection is never attempted.
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.
mysql
Тільки процедурний стиль: об'єкт mysqli, якого повертає функція mysqli_connect() або mysqli_init()
Якщо увімкнені звіти про помилки
mysqli (MYSQLI_REPORT_ERROR
) і запитана операція не
виконалась, буде виведено попередження, але якщо встановлено режим
MYSQLI_REPORT_STRICT
, буде викинуто виключення
mysqli_sql_exception.
Версія | Опис |
---|---|
8.4.0 |
Both mysqli::ping() and
mysqli_ping() are now deprecated.
The reconnect feature has not been available
as of PHP 8.2.0, making this function obsolete.
|
Приклад #1 mysqli::ping() example
Об'єктно-орієнтований стиль
<?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!