MySQL – Connect with PHP (mysqli)

——————————————————————————–
https://www.youtube.com/embed/OCXC6lXHtMg

Find code and diagrams at: https://www.EliTheComputerGuy.com

You can use the built in MySQLi Extension with PHP to connect your PHP scripts to a MySQL Database.

Environment – LAMP stack on Ubuntu 18.04 Desktop using tasksel

gEdit – Preferences – Display Line Numbers, Highlight matching brackets

Create Apache Accessible Directory with user write permission

sudo mkdir /var/www/html/php

sudo chown username /var/www/html/php
PHP Code (connectTest.php)

?php

$servername = “localhost”;
$username = “username”;
$password = “password”;

$conn = new mysqli($servername, $username, $password);

if ($conn-connect_error) {
die(“Connection failed: ” . $conn-connect_error);
}

echo “Connected successfully”;

?