Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> MySQL

Xóa bảng MySQL bằng PHP script (mysql_query)

PHP dùng mysql_query để xóa bảng MySQL.

Ví dụ

Xóa bảng Tutorials_tbl:

<html>
  <head>
    <title>Creating MySQL Tables</title>
  </head>
  <body>
    <?php
      $dbhost = 'localhost:3036';
      $dbuser = 'root';
      $dbpass = 'rootpassword';
      $conn = mysql_connect($dbhost, $dbuser, $dbpass);
      if(! $conn ) {
        die('Could not connect: ' . mysql_error());
      }
      echo 'Connected successfully<br />';
      $sql = "DROP TABLE tutorials_tbl";
      mysql_select_db('TUTORIALS');
      $retval = mysql_query( $sql, $conn );
      if(! $retval ) {
        die('Could not delete table: ' . mysql_error());
      }
      echo "Table deleted successfully\n";
      mysql_close($conn);
    ?>
  </body>
</html>

Lưu ý: mysql_* deprecated, dùng mysqli_query hoặc PDO.