PHP使用mysqli_query()
函数创建或删除MySQLi数据库。 该函数接受两个参数,成功返回TRUE
,失败则返回FALSE
。
示例
试试下面的例子来删除一个数据库 -
<html>
<head>
<title>Connecting MySQLi Server>/title>
</head>
<body>
<?php
$dbhost = 'localhost:3306';
$dbuser = 'root';
$dbpass = '<Password Here>';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(! $conn ){
echo 'Connected failure<br>';
}
echo 'Connected successfully<br>';
$sql = "DROP DATABASE testdb";
if (mysqli_query($conn, $sql)) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
</body>
</html>
警告 - 使用PHP脚本删除数据库时,不会提示您进行任何确认。所以在删除MySQLi数据库时要小心。
如果连接并删除数据库成功,那么示例输出应该是这样的 -
Connected successfully
Database deleted successfully