PHP mysqli ping() İşlevi
Örnek - Nesne Yönelimli stil
Bir sunucu bağlantısına ping işlemi yapın:
<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");
// Check connection
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
// Check if server is alive
if ($mysqli -> ping()) {
echo "Connection is ok!";
} else {
echo "Error: ".
$mysqli -> error);
}
$mysqli -> close();
?>
En alttaki prosedürel stil örneğine bakın.
Tanım ve Kullanım
ping() / mysqli_ping() işlevi, sunucunun canlı olup olmadığını kontrol etmek için bir sunucu bağlantısına ping gönderir. Ayrıca bağlantı kesilirse yeniden bağlanmayı dener.
Sözdizimi
Nesne yönelimli stil:
$mysqli -> ping()
Prosedür stili:
mysqli_ping(connection)
Parametre Değerleri
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to use |
Teknik detaylar
Geri dönüş değeri: | Başarı konusunda DOĞRU. Başarısızlıkta YANLIŞ |
---|---|
PHP Sürümü: | 5+ |
Örnek - Prosedür stili
Bir sunucu bağlantısına ping işlemi yapın:
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
// Check if server is alive
if (mysqli_ping($con)) {
echo "Connection is ok!";
} else {
echo "Error: ". mysqli_error($con);
}
mysqli_close($con);
?>
❮ PHP MySQLi Referansı