Sat. Dec 7th, 2019

Host your Website

Read and learn

FatCow Web Hosting $1.00/mo* Trust your web hosting to the #1 web host provider, GoDaddy!

MySQL – Connect with PHP (mysqli)

1 min read

Find code and diagrams at:

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)


$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”;


7 thoughts on “MySQL – Connect with PHP (mysqli)

Comments are closed.

Copyright © All rights reserved. | Newsphere by AF themes.