Check server connection:
<?php // Assume database username: root, password: 123456, database: CODERCTO $con=mysqli_connect("localhost","root","123456","CODERCTO"); if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // Check whether the MySQL server is available if (mysqli_ping($con)){ echo "Connection OK!";}else{ echo "Error: ". mysqli_error($con);}mysqli_close($con);?>
The mysqli_ping() function makes a server connection and attempts to reconnect if the connection has been disconnected.
mysqli_ping( connection ) ;
parameter | describe |
---|---|
connection | Required. Specifies the MySQL connection to use. |
Return value: | Returns TRUE if successful and FALSE if failed. |
---|---|
PHP version: | 5+ |