1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 5.00 out of 5)

Connect to a Database Using PHP MySqli

In order to Connect to a Database Using PHP MySqli be sure that you have the following procedures done.


Tip: Click on images to make them larger. If you find anything wrong on this page or need further assistance please comment below or contact me. 🙂
  1. You Created A Database
  2. You Granted Privileges to the database
  3. Created a config.php file to access the database

Now that you have done the three required steps you can use the following code to connect to a database in order to manipulate it. As long as you have granted  the right permissions like in step 2 above you will be able to Update, Insert and Delete information in a database.

if($con->connect_errno > 0){
die('Unable to connect to database [' . $con->connect_error . ']');
}else{echo "Connected successfully!";};

Connect to a Database Using PHP MySqli

This piece of code only connects you to the database. It does not do anything else. We will have to write code in order to insert values into the table rows that we created previously. Be sure that you are cognizant about the file paths. If you do not have the file paths correct you will not be able to connect.

Subscribe To My YouTube Channel:


Connect to a Database Using PHP MySqli was last modified: October 20th, 2015 by Maximus Mccullough

Please like, share and subscribe.

Advanced Programming Made Easy

I hope you enjoyed the article. If I was able to help you please consider a tip for the content.

One Time Tip

more tips

Reoccuring Tips


Cool People Share:
Connect to a Database Using PHP MySqli

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.