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.

[code]// 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;
}

Only cool people share!

$con->close();[/code]

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.

Video Instructions

Create a MySql Database in PHP in MySqli was last modified: October 18th, 2015 by Maximus Mccullough
Summary
Create a MySql Database in PHP in MySqli
Article Name
Create a MySql Database in PHP in MySqli
Description
In order to Create a MySql Database in PHP with MySqli you will need to have the following set up before you proceed. Hosting plan A FTP or sFTP connection in order to upload files. The login to your cPanel in order to create a database and user privileges.
Author
create-a-php database-with-mysqli

Leave a Reply

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