You can delete the database in the same manner as you created the database using the mysql_query function.
Example
<?php $db_host = 'localhost:3036'; $db_user = 'root'; $db_pass = 'rootpassword'; $db_conn = mysql_connect($db_host, $db_user, $db_pass); if(! $db_conn ) { die('Error: ' . mysql_error()); } echo 'Success'; $db_sql = 'DROP Database demo_db'; $db_retval = mysql_query( $sql, $conn ); if(! $db_retval ) { die('Database deletion failed: ' . mysql_error()); } echo "Database demo_db deleted\n"; mysql_close($db_conn); ?>
Deleting table within the database using PHP
Make sure that you are deleting the right table and database else you may lose some important data.
Example
<?php $db_host = 'localhost:3036'; $db_user = 'root'; $db_pass = 'rootpassword'; $db_conn = mysql_connect($db_host, $db_user, $db_pass); if(! $db_conn ) { die('Connection failed: ' . mysql_error()); } echo 'Success'; $db_sql = 'DROP table students'; mysql_select_db('demo_db'); $db_retval = mysql_query( $db_sql, $conn ); if(! $db_retval ) { die('Table deletion failed: ' . mysql_error()); } echo "Table student deleted successfully\n"; mysql_close($db_conn); ?>
People are also reading: