-
Notifications
You must be signed in to change notification settings - Fork 0
/
createDatabase.php
47 lines (39 loc) · 1.26 KB
/
createDatabase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Student_Database";
$tablename = "student";
$message = "";
// Create connection
$con = mysqli_connect($servername, $username, $password);
// Check connection
if (!$con) {
$message = "Not connected to server";
}
//echo "Connected successfully";
if(!mysqli_select_db($con,$dbname))
{
$message = "Database not selected";
}
//Create database named 'Student_Database'
$sql_createDB = "CREATE DATABASE ".$dbname;
if(!mysqli_query($con,$sql_createDB)){
$message = "Database cannot be created.";
}
//Select the database just created
if(!mysqli_select_db($con,$dbname))
{
$message = "Database not selected";
}
//Create the table named Student
$sql_createTB = "CREATE TABLE ".$tablename."( Name VARCHAR(255) NOT NULL,Roll_Number INT(9) UNSIGNED PRIMARY KEY, Department VARCHAR(20) NOT NULL, Email VARCHAR(255), Address VARCHAR(255),About VARCHAR(255),Passcode VARCHAR(6))";
if(mysqli_query($con,$sql_createTB)){
$message = "Database 'Student_Database' created successfully.\n\nTable 'Student' created successfully.";
}
else
{
$message = "Database 'Student_Database' created successfully.\n\nTable 'Student' cannot be created.";
}
echo nl2br($message);
?>