php mysqli connection check
/* Procedural style */
<?php
$conn = mysqli_connect("localhost", "user", "password", "database");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* check if server is alive */
if (mysqli_ping($conn)) {
printf ("Our connection is ok!\n");
} else {
printf ("Error: %s\n", mysqli_error($conn));
}
/* close connection */
mysqli_close($conn);
?>