Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php mysqli connection check

/* 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);
?>
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #php #mysqli #connection #check
ADD COMMENT
Topic
Name
2+4 =