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