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

Write A PHP Script To Create A Database, Create Table and Delete The Database

Uploaded by

mynameyourname58
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Write A PHP Script To Create A Database, Create Table and Delete The Database

Uploaded by

mynameyourname58
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Question 1

Write a Php script to create a database, create table and delete the database.

<html>
<head>
<title>Program 1</title>
</head>
<body>
<form action="" method="post">
<input type="submit" value="Create Database" name="createDB">
<input type="submit" value="Create Table" name="createTB">
<input type="submit" value="Delete Database" name="del">
</form> <br><br>

<?php

$servername = "localhost"; //if your post no. is not 3306, then you need to manually type the port number here..
$username = "root";
$pwd = "";

$con = new mysqli($servername, $username, $pwd);

if ($con) {
echo "Connection Established<br>";
} else {
die("Connection failed: " . $con -> connect_error);
}

if (isset($_POST["createDB"])) {
$sql = "create database mydbaa";

if ($con -> query($sql) === TRUE) {


echo "Database created successfully";
} else {
die("Error creating database: " . $con -> error);
}
}

if (isset($_POST["createTB"])) {
$con = new mysqli($servername, $username, $pwd, "mydbaa");

$sql = "create table details(Name varchar(30) not null,


Age varchar(30) not null)";

if ($con -> query($sql) === TRUE) {


echo "Table \"details\" created successfully";
} else {
echo "Error creating table: " . $con -> error;
}
}

if (isset($_POST["del"])) {
$sql = "drop database mydbaa";
$res = $con -> query($sql);

Question 1 1
if ($res) {
// echo var_dump($res);
echo "<br>Database is deleted";
} else {
die("Some exception occured");
}
}

?>
</body>
</html>

Output:

Question 1 2

You might also like