PHP | mysqli_ping() Function Last Updated : 18 Jan, 2022 Comments Improve Suggest changes Like Article Like Report The mysqli_ping() function is used to ping a server connection. That is it is used to check if a host is reachable on an IP network or not. This function also tries to reconnect if an existing server connection is lost. To use this function, it is mandatory to first set up the connection with the MySQL database.This function can be used in both Object Oriented and Procedural styles as described below: Object oriented style:Syntax:ping();Parameters: This function does not accepts any parameter, it is used with a connection instance.Return Value: This function returns True on success and False on failure.Below program illustrate the ping() function in object-oriented style: PHP <?php $servername = "localhost"; $username = "username"; $password = "password"; // Creating a connection $conn = new mysqli($servername, $username, $password); // Check connection if ($conn->connect_error) { die("Connection to the server failed: " . $conn->connect_error); } /* check if server is alive */ if ($conn->ping()) { printf ("Successful Connection!\n"); } else { printf ("Error: %s\n", $conn->error); } /* close connection */ $conn->close(); ?> Procedural style:Syntax:mysqli_ping($conn);Parameters: This function accepts a single parameter $conn which represents the connection to use.Return Value: This function returns True on success and False on failure.Below program illustrate the mysqli_ping() in the procedural style: PHP <?php $$servername = "localhost"; $username = "username"; $password = "password"; // Creating connection $conn = mysqli_connect($servername, $username, $password); // Checking connection if (!$conn) { die("Connection to the server failed: " . mysqli_connect_error()); } /* check if server is alive */ if (mysqli_ping($conn)) { printf ("Successful Connection!\n"); } else { printf ("Error: %s\n", mysqli_error($conn)); } /* close connection */ mysqli_close($conn); ?> Reference: http://php.net/manual/en/mysqli.ping.php Comment More infoAdvertise with us Next Article PHP | mysqli_ping() Function K KRV Follow Improve Article Tags : PHP Web Technologies Similar Reads PHP | mysqli_error() Function The mysqli_error() function is used to return the error in the most recent MySQL function call that failed. If there are multiple MySQL function calls, the error in the last statement is the one that is pointed out by the function. Syntax: mysqli_error("database_name") Parameters: This function acce 1 min read PHP | mysqli_close() Function MySQLi Procedural procedure: To close the connection in mysql database we use php function mysqli_close() which disconnect from database. It require a parameter which is a connection returned by the mysql_connect function. Syntax: mysqli_close(conn); If the parameter is not specified in mysqli_close 2 min read PHP | mysqli_num_rows() Function The mysqli_num_rows() function is an inbuilt function in PHP which is used to return the number of rows present in the result set. It is generally used to check if data is present in the database or not. To use this function, it is mandatory to first set up the connection with the MySQL database. Sy 2 min read PHP mysqli_connect() Function The mysqli_connect() function in PHP is a fundamental tool for establishing a connection to a MySQL database. This function is crucial for PHP applications that need to interact with MySQL databases, enabling them to execute queries, retrieve data, and perform various database operations.In this art 3 min read PHP | mysqli_real_escape_string() Function The mysqli_real_escape_string() function is an inbuilt function in PHP which is used to escape all special characters for use in an SQL query. It is used before inserting a string in a database, as it removes any special characters that may interfere with the query operations. When simple strings ar 2 min read PHP | inet_pton() Function The inet_pton() function is an inbuilt function in PHP which converts a readable format IP address into a packed 32bit IPv4 or 128bit IPv6 address. Syntax: string inet_pton( string $ip_address ) Parameters: This function accepts single parameter as mentioned above and described below: $ip_address: I 1 min read PHP | link( ) Function The link() creates a hard link for a specified target. The target and the link are passed as parameters to the link() function and it returns true on success and false on failure.Syntax: link(target, link)  Parameters Used: The link() function in PHP accepts two parameters. target : It is a manda 2 min read PHP | mysqli_fetch_array() Function The mysqli_fetch_array() function is used to fetch rows from the database and store them as an array. The array can be fetched as an associative array, as a numeric array or both. Associative arrays are the arrays where the indexes are the names of the individual columns of the table. On the other h 2 min read PHP | long2ip() Function The long2ip() function is an inbuilt function in PHP which converts long integer into corresponding IPv4 address in string format. Syntax: string long2ip( int $ip_in_long ) Parameters: This function accepts single parameter as mentioned above and described below: $ip_in_long: It is required paramete 1 min read PHP | sleep( ) Function The sleep() function in PHP is an inbuilt function which is used to delay the execution of the current script for a specified number of seconds. The sleep( ) function accepts seconds as a parameter and returns TRUE on success or FALSE on failure. If the call is interrupted by a signal, sleep() funct 2 min read Like