How To Use SQL CREATE DATABASE STATEMENT Using PHP

admin_img Posted By Bajarangi soft , Posted On 18-09-2020

CREATE DATABASE statement is used to create a new SQL database to store data.

SQL CREATE DATABASE Statement

Syntax CREATE DATABASE Statement

CREATE DATABASE databasename;​

give unique database name 
 


Example(1)

CREATE DATABASE New_data_base;

above SQL statement creates a database called "New_data_base".

 

2.Complete code of CREATE DATABASE Statement  in PHP script.
we can also create database by executing file .
 

<!DOCTYPE html>
<html lang="en">
<head>
    <title>SQL CREATE DATABASE Statement</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
    <br>
    <br>
    <br>
    <div class="text-center">
        <h1>SQL CREATE DATABASE Statement</h1>
    </div>
    <br>
    <br>
    <br>

    <div class="well">
        <?php
        $connect = mysqli_connect("localhost", "root", "", "school_management");
        if($connect === false){
            die("ERROR: Could not connect. " . mysqli_connect_error());
        }
        $sql = "CREATE DATABASE New_data_base";
        if(mysqli_query($connect, $sql)){
            echo "<br><h1 class='text-success'>Database created  successfully.</h1>";
        } else{
            echo "ERROR: Could not able to execute $sql. " . mysqli_error($connect);
        }
        mysqli_close($connect);
        ?>
    </div>
    <br>
</div>
</body>
</html>

Related Post