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";
?>
Be the first to comment