xmtrinidad
2/4/2018 - 4:42 PM

PHP DB Connect using mysqli

Basic set-up to connect to a database using mysqli

<?php

$dbServername = "localhost"; // For local development
$dbUsername = "root";
$dbPassword = "DBPW";
$dbName = "DBNAME";

$mysqli = new mysqli($dbServername, $dbUsername, $dbPassword, $dbName);

// Connection error check
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}