0% found this document useful (0 votes)
30 views2 pages

PHP Create A MySQL Database

The document discusses how to create a MySQL database using PHP. It provides code examples to create a database called 'myDB' using MySQLi and PDO. It notes that special CREATE privileges are required and that the database will consist of tables.

Uploaded by

Saripilli Vasu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
30 views2 pages

PHP Create A MySQL Database

The document discusses how to create a MySQL database using PHP. It provides code examples to create a database called 'myDB' using MySQLi and PDO. It notes that special CREATE privileges are required and that the database will consist of tables.

Uploaded by

Saripilli Vasu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 2

PHP 

Create a MySQL Database


❮ PreviousNext ❯

A database consists of one or more tables.

You will need special CREATE privileges to create or to delete a MySQL


database.

Create a MySQL Database Using MySQLi


and PDO
The CREATE DATABASE statement is used to create a database in MySQL.

The following examples create a database named "myDB":

Example (MySQLi Object-oriented)


<?php
$servername = "localhost";
$username = "username";
$password = "password";

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

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

$conn->close();
?>
Note: When you create a new database, you must only specify the first three
arguments to the mysqli object (servername, username and password).

Tip: If you have to use a specific port, add an empty string for the database-
name argument, like this: new mysqli("localhost", "username", "password",
"", port)

You might also like