Drop My Sql Database

Drop Database using PHP Script

PHP uses mysql_query function to create or delete a MySQL database. This function takes two parameters and returns TRUE on success or FALSE on failure.


bool mysql_query( sql, connection );
Parameter Description
sql Required – SQL query to create or delete a MySQL database
connection Optional – if not specified, then last opened connection by mysql_connect will be used.


Try the following example to delete a database:

<title>Deleting MySQL Database</title>
$dbhost = 'localhost:80';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
  die('Could not connect: ' . mysql_error());
echo 'Connected successfully<br />';
$sql = 'DROP DATABASE shiksha360';
$retval = mysql_query( $sql, $conn );
if(! $retval )
  die('Could not delete database: ' . mysql_error());
echo "Database Shiksha360 deleted successfully\n";

WARNING: While deleting a database using PHP script, it does not prompt you for any confirmation. So be careful while deleting a MySQL database.

Admin has written 171 articles

Leave a Reply