The goal of this script is to delete a database on the MySQL server. To do so, you simply have to modify the query used in the previous script.
Open db_createdb.php in your text editor.
Change the value of the $sql variable to
$sql = "DROP DATABASE testDB2";
Change the error message and the HTML title to reflect the fact that you want to delete a database and not create one.
Your code should look something like this:
<?
$sql = "DROP DATABASE testDB2";
$connection = @mysql_connect("localhost","spike","9sj7En4")
or die(mysql_error());
$result = @mysql_query($sql,$connection) or die(mysql_error());
if ($result) {
$msg ="<P>Database has been deleted!</P>";
}
?>
<HTML>
<HEAD>
<TITLE>Delete a MySQL Database</TITLE>
</HEAD>
<BODY>
<? echo "$msg"; ?>
</BODY>
</HTML>
Save the file with the new name db_dropdb.php, and place this file in the document root of your web server.
Open your web browser and type http://127.0.0.1/db_dropdb.php.
If the database deletion was successful, you'll see the message shown in the following figure.
In the next chapter, you create a database table for keeps, and you eventually populate that table with some data.