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

Create a MySql Database in PHP in MySqli

In order to Create a MySql Database in PHP in MySqli you will need to have the following set up before you proceed.

  1. Hosting plan
  2. A FTP or sFTP connection in order to upload files.
  3. The login to your cPanel in order to create a database and user privileges.

Here is the code you will need to create a database in PHP. This will create a database called myDB.

// Create connection
$con= new mysqli($servername, $username, $password);
// Check connection
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}

// Create database
$sql = "CREATE DATABASE myDB";
if ($con->query($sql) === TRUE) {
echo "Database created successfully";
} else {
echo "Error creating database: " . $con->error;
}

$con->close();

Instructions for creating a database with MySqli in PHP *

For the server name use the ip address. That may save you a lot of headaches in the long run. Your username will be the username that you use to sign into your cPanel or your hosting account. you will also use the same password that you use to log into your cPanel or hosting  account. This is first time that you will use this information to create databases in your hosting accounts.

You will not need this information when you are creating tables or rows in a mysql database.  You will just need the username and password for each database itself.  The next post will discuss creating user privileges in each database. You need to get this though your head now. yes you will have 2 different usernames and passwords. One to create databases and user privileges and the other usernames and passwords for each database itself.

Subscribe To My YouTube Channel:

Video Instructions *

Create a MySql Database in PHP in MySqli was last modified: October 18th, 2015 by Maximus Mccullough

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

Tips

create-a-php database-with-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.