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.

 

  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.

[code]

include(‘config.php’);
if($con->connect_errno > 0){
die(‘Unable to connect to database [‘ . $con->connect_error . ‘]’);
}else{echo "Connected successfully!";};[/code]

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.

 

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

Summary
Connect to a Database Using PHP MySqli
Article Name
Connect to a Database Using PHP MySqli
Description
In order to Connect to a Database Using PHP MySqli be sure that you have the following procedures done. Created Database, Granted Privileges, a config file
Author
Connect to a Database Using PHP MySqli

Leave a Reply

Your email address will not be published.