<?php
// Code to create the database
$serverName = "localhost";
$userName = "username";
$password = "password";
// Create the Database Connection
$connId = mysqli_connect($serverName, $userName, $password);
// Check the Database Connection
if ($connId === false)
{
exit("ERROR: Could not connect. " . mysqli_connect_error());
}
// Create the Database
$sql = "CREATE DATABASE yourDatabaseName";
// Check that the Database was created
if (mysqli_query($connId, $sql))
{
echo "Database created successfully";
}
else
{
echo "ERROR: Creating Database. " . mysqli_error($connId);
}
// Close the Connection
mysqli_close($connId);
?>
// Code to create database tables
<?php
$serverName = "localhost";
$userName = "username";
$password = "password";
// Attempt MySQL server connection. Assuming you are running MySQL server
$connId = mysqli_connect($serverName, $userName, $password);
// Check connection
if ($connId === false)
{
exit("ERROR: Could not connect. " . mysqli_connect_error());
}
// Attempt create table query execution
$sql = "CREATE TABLE persons(person_id INT(4) NOT NULL PRIMARY KEY AUTO_INCREMENT, first_name CHAR(30) NOT NULL, last_name CHAR(30) NOT NULL, email_address VARCHAR(50))";
if (mysqli_query($connId, $sql))
{
echo "Table persons created successfully";
}
else
{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($connId);
}
// Close connection
mysqli_close($connId);
?>