Home >Backend Development >PHP Problem >How to delete the entire database in php
In PHP, you can delete the database through the mysqli_query function. Delete statements such as "mysqli_connect($dbhost, $dbuser, $dbpass);$sql = 'DROP DATABASE XXX';".
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
How to delete the entire database with php?
Use PHP script to delete database
PHP uses the mysqli_query function to create or delete a MySQL database.
This function has two parameters and returns TRUE when executed successfully, otherwise it returns FALSE.
Syntax
mysqli_query(connection,query,resultmode);
Parameters
connection required. Specifies 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 (default)
Example
The following example demonstrates the use of PHP mysqli_query function to delete a database:
Delete database
<?php $dbhost = 'localhost'; // mysql服务器主机地址 $dbuser = 'root'; // mysql用户名 $dbpass = '123456'; // mysql用户名密码 $conn = mysqli_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('连接失败: ' . mysqli_error($conn)); } echo '连接成功<br />'; $sql = 'DROP DATABASE RUNOOB'; $retval = mysqli_query( $conn, $sql ); if(! $retval ) { die('删除数据库失败: ' . mysqli_error($conn)); } echo "数据库 RUNOOB 删除成功\n"; mysqli_close($conn); ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to delete the entire database in php. For more information, please follow other related articles on the PHP Chinese website!