Home  >  Article  >  Backend Development  >  How to delete data table using PHP script

How to delete data table using PHP script

WJ
WJOriginal
2020-06-01 11:06:012758browse

How to delete data table using PHP script

How to use PHP script to delete a data table:

Deleting a data table in MySQL is very easy to operate, but you can delete the table again Be very careful while doing this because all data will disappear after executing the delete command.

The following is the general syntax for deleting MySQL data tables:

DROP TABLE table_name ;

Use PHP script to delete data tables

PHP uses the mysqli_query function to delete MySQL data tables.

This function has two parameters and returns TRUE when executed successfully, otherwise it returns FALSE.

Grammar

mysqli_query(connection,query,resultmode);
<?php
$dbhost = &#39;localhost:3306&#39;;  // mysql服务器主机地址
$dbuser = &#39;root&#39;;            // mysql用户名
$dbpass = &#39;123456&#39;;          // mysql用户名密码
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(! $conn ){  
die(&#39;连接失败: &#39; . mysqli_error($conn));}
echo &#39;连接成功<br />&#39;;
$sql = "DROP TABLE runoob_tbl";
mysqli_select_db( $conn, &#39;RUNOOB&#39; );
$retval = mysqli_query( $conn, $sql );
if(! $retval ){  die(&#39;数据表删除失败: &#39; . mysqli_error($conn));}
echo "数据表删除成功\n";mysqli_close($conn);?>

Related references:php中文网

The above is the detailed content of How to delete data table using PHP script. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn