我需要通过在下面的代码中传递 a 和 b 的值来删除数据库
我已将 a 的值设置为 5 用于第一级测试,并将 b 的值设置为数据库名称
即 index.php?a=5&b=test
<?php
include ('config.php');
$a=$_GET["a"];
$b=$_GET["b"];
if ($a==5)
{
$sql = 'drop database'.'$db';
if (mysql_query($sql))
{
echo "Database test was successfully dropped\n";
}
else
{
echo 'Error dropping database: ' . mysql_error() . "\n";
}
}
{
echo "Not Success";
}
?>
我遇到了错误
Error dropping database: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'databasee$db' at line 1 Not Success
我知道我不能在 php 中通过 mysql 查询删除数据库
Error Dropping Database (Can't rmdir '.test\', errno: 17)
错误是代码中包含数据库名
$sql='drop database'.'$b';
我该怎么做?
最佳答案
你忘了加空格..而且单引号下的变量不会被解析
正确的做法...
$sql = "drop database ".$db;
^------ Here
关于php - 通过在 url 中传递值来删除数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22215922/