MySQLi - Ping



Syntax

bool mysqli_ping ( mysqli $link )

Definition and Usage

It is used to ping a server.

Example

Try out following example −

<?php
   $servername = "localhost:3306";
   $username = "root";
   $password = "";
   $dbname = "TUTORIALS";
   $conn = new mysqli($servername, $username, $password, $dbname);

   if ($conn->connect_error) {
      die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
      exit();
   } 
   
   if (!mysqli_query($conn, "SET a = 1")) {
      printf("Errorcode: %d\n", mysqli_error($conn));
   }
   echo 'Success... ' . mysqli_get_host_info($conn) . "\n";
   
   if ($conn->ping()) {
      printf ("Our connection is ok!\n");
   } else {
      printf ("Error: %s\n", $conn->error);
   }
   $conn->close();
?>

The sample output of the above code should be like this −

Errorcode: 0 Success... localhost:3306 via TCP/IP Our connection is ok!
mysqli_useful_functions.htm
Advertisements