Deleting a table in MySQL is very easy, but you need to be very careful when deleting a table because all data will disappear after you run the delete command.
grammar
MySQL > alter table drop MySQL > alter table drop
DROP TABLE table_name ;
Copy the code
Delete the table in the command prompt window
Mysql > DROP TABLE;
The instance
The following example drops the table runoob_tbl:
root@host# mysql -u root -p
Enter password:*******
mysql> use RUNOOB;
Database changed
mysql> DROP TABLE runoob_tbl
Query OK, 0 rows affected (0.8 sec)
mysql>
Copy the code
Delete the data table using the PHP script
PHP uses the mysqli_query function to drop the MySQL table.
This function takes two arguments and returns TRUE on success and FALSE otherwise.
grammar
mysqli_query(connection,query,resultmode);
Copy the code
parameter | describe |
---|---|
connection | A necessity. Specify the MySQL connection to use. |
query | Required, specifies the query string. |
resultmode | Optional. A constant. Can be any of the following values: * MYSQLI_USE_RESULT (use this if you need to retrieve large amounts of data) |
- | MYSQLI_STORE_RESULT (the default)
The instance
The following example uses a PHP script to drop the table runoob_tbl:
Deleting a Database
<? php $dbhost = ‘localhost’; $dbuser = ‘root’; $dbpass = ‘123456’; $conn = mysqli_connect($dbuser, $dbpass); if(! $conn) {die(‘ connection failed: ‘. Mysqli_error ($conn)); } echo ‘connect successfully <br />’ $sql = “DROP TABLE runoob_tbl”; mysqli_select_db( $conn, ‘RUNOOB’ ); $retval = mysqli_query( $conn, $sql ); if(! $retval) {die(‘ mysqli_error($conn)); } echo “select * from db; mysqli_close($conn); ? >
After successful execution, the ruNOob_tbL table is not visible with the following command:
mysql> show tables; The Empty set (0.01 SEC)Copy the code