Drop MySQL Database using PHP

Drop MySQL Database using PHP

Drop MySQL Database using PHP

 

Drop MySQL Database using PHP, in this article i will step through how to drop / delete a mySQL Data base using PHP.

Prior to that you need to complete  the items listed Below

  1. Mamp or xampp with phpMyAdmin install into your Computer , check out here
  2.  A Sample Database created Check out Here
  3.  New User Created . Check out Here

Step 1

Start your My SQL and Apache Server

mysql and Apache Initialised Success
mysql and Apache Initialised Success

 

Step 2

Create a new Script

(1) First to connect to the Database

(2) Delete the Data Base from MySQL


<?php /* Declare User connecting Credential*/ $hostName ="localhost"; $userName ="jane"; $userPassword ="jane"; $dataBaseName = "mydata"; /* return connection status through $dbConnectionStatus Boolean Variable*/ /* using mysqli Object*/ $dbConnectionStatus = new mysqli($hostName, $userName, $userPassword,$dataBaseName); /* Check whether the User Succesfully connect to localhost and mydata Database*/ /* -> Access the instance "$dbConnectionStatus" variable property "connect_error " boolean */

if ($dbConnectionStatus->connect_error){

die("Connection failed: " . $dbConnectionStatus->connect_error);

}else{

echo " Database Connected " ;
echo "
";
}

$sql = "DROP DATABASE mydata ";

/* Execute query to delete " anotherdata Data base " */

$deleteStatus =$dbConnectionStatus->query($sql);

/*Check Whether Data Base Successuly Deleted*/
if($deleteStatus){

echo"Data Base deleted \n";

}else {

echo"Data Base delete Unsuccessful \n";
}

?>

Step 3

Save this File as “.php” extension in

C:\xampp\htdocs

 

If you want to change the root Location of the mySQL file check out this  article at step 3

 

Step 4

Before   executing the new PHP  file created above   , check whether  the database that you intend to delete , is in mySQL

In this example the database name is called :  “mydata “

 

check your database
check your database

 

Step 5

Test it

(1)Click Admin

(2) Click the  PHP File you have just created  in this example i name it  ” dropDatabase2.php”

click the drop database php file
click the drop database php file

If  Database drop successfully  the browser .

 

mysql database deleted
mysql database deleted

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

four × 5 =