php mysqli connection check

Solutions on MaxInterview for php mysqli connection check by the best coders in the world

showing results for - "php mysqli connection check"
Elisa
14 Aug 2017
1/* Procedural style */
2<?php
3 
4$conn = mysqli_connect("localhost", "user", "password", "database");
5
6/* check connection */
7if (mysqli_connect_errno()) {
8    printf("Connect failed: %s\n", mysqli_connect_error());
9    exit();
10}
11
12/* check if server is alive */
13if (mysqli_ping($conn)) {
14    printf ("Our connection is ok!\n");
15} else {
16    printf ("Error: %s\n", mysqli_error($conn));
17}
18
19/* close connection */
20mysqli_close($conn);
21?>
22