w3resource logo


PHP mysql_ping function

PHP : mysql_ping() function

rating has average rating 1 out of 10. Total 1 users rated.

<<PreviousNext>>

Description

The mysql_ping() function is used to ping a server connection or reconnect if there is no connection.

Version

(PHP 4 and above)

Syntax

mysql_ping(connection)

Parameter

Name Description Required/ Optional Type
connection The MySQL connection. Before performing any operation on a MySQL database, it is required to set a connection to the mysql database you want to work with. And this is done by mysql_connect() function. This function takes three parameters, name of the host, username with which you want to perform tasks with the mysql database in question, and password of that user. As soon as a successful connection is established, you can perform the operations on that mysql database. In case, no such connection is found, it will try to create one without any arguments, i.e. mysql_connect() without any parameters. If it fails to connect to a mysql database, it will generate a warning (E_WARNING) but not an error. Optional Resource

Return value

TRUE if the connection to MySQL server is successful, otherwise FALSE.

Value Type : Boolean.

Example :

<?php
$con = mysql_connect("localhost", "root", "mypass");
$selectdb = mysql_select_db("tutorials",$con)
$sql = "select * from tutorials";
$result = mysql_query($sql);
if (!mysql_ping($conn)) {
    echo 'Lost connection, exiting after query #1';
    exit;
}
mysql_free_result($result);
$sql_next = "select name, no_of_pages, author from tutorials where name = 'html' ";
$result_next = mysql_query($sql_next);
$row_next = mysql_fetch_array($result_next);
echo $row['name'].",".$row['no_of_pages'].",".$row['athor'];
?> 

See also

PHP Function Reference

mysql_thread_id()

mysql_list_processes()

<<PreviousNext>>