PHP MySQL tutorial

Drop Database in MySQL via PHP Script

In the last article we saw how to create a database in PHP via object oriented as well as procedural PHP. In this article, we shall see how to delete database using object oriented and procedural MySQLi.To delete a database, DROP query is used. The syntax of DROP query is as follows.

DROP DATABASE dbname

Drop Database via Object Oriented MySQLi

To drop a database via PHP is simple. Pass the query to drop database to the query function of the mysqli object and rest of the task will be done by PHP. Have a look at this example.




Using MySQLi to Drop MySQL Table



connect_error) {
    die("Connection not established: " . $connection->connect_error);
} 
    
// Drop Database
$query = "DROP DATABASE Patient";
if ($connection->query($query) === TRUE) {
    echo "Database dropped successfuly.";
} else {
    echo "Unable to drop database " . $connection->error;
}

$connection->close();
?>
        



Download the code

The above code will drop database named ‘Patient’ from the server.

Drop Database via Procedural MySQLi

For procedural MySQLi database creation simple replace mysqli object creation with mysqli_connect function. Have a look at the following example.




Using MySQLi to drop MySQL Table



connect_error) {
    die("Connection not established: " . $connection->connect_error);
} 
    
// Dropping Database
$query = "DROP DATABASE Patient";
if ($connection->query($query) === TRUE) {
    echo "Database dropped successfuly.";
} else {
    echo "Unable to drop database " . $connection->error;
}

$connection->close();
?>
      



Download the code

<<< Create Database in MySQL via PHP ScriptSelecting Mysql Database via PHP Script >>>
Copyright 2005-2016 KnowledgeHills. Privacy Policy. Contact .