Home >Backend Development >PHP Problem >What is the statement to delete the database in php mysql

What is the statement to delete the database in php mysql

藏色散人
藏色散人Original
2021-09-21 14:52:072513browse

php The statement for mysql to delete the database is "DROP DATABASE". The specific deletion method is: 1. Connect to mysql through the mysqli_connect function; 2. Delete the database through the "DROP DATABASE" statement and the "mysqli_query" function. .

What is the statement to delete the database in php mysql

The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

php What is the statement for mysql to delete a 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 the PHP mysqli_query function to delete the database:

Delete the database

<?php
$dbhost = &#39;localhost&#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 = &#39;DROP DATABASE RUNOOB&#39;;
$retval = mysqli_query( $conn, $sql );
if(! $retval )
{
    die(&#39;删除数据库失败: &#39; . mysqli_error($conn));
}
echo "数据库 RUNOOB 删除成功\n";
mysqli_close($conn);
?>

After successful execution, the result is:

What is the statement to delete the database in php mysql

Note: When using a PHP script to delete a database, no confirmation message will appear. The specified database will be deleted directly, so you should be particularly careful when deleting the database.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is the statement to delete the database in php mysql. 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