我已经搜索了几十个与这篇文章几乎相同的标题的问题,但我还没有找到我的具体问题的答案。我正在尝试准备一份声明,但每次都会收到此错误。我认为我的sql语法上必定存在某种错误,但对于我的生活,我找不到它。
$title = "this_is_my_table_title";
//import the database login credential variables
require("localhost_credentials.php");
$conn = new mysqli($db_servername, $db_username, $db_password, $db_name);
if($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
$querystr = "CREATE TABLE ? (";
$querystr .= "id int(11) not null auto_increment,";
$querystr .= "section varchar(255) not null,";
$querystr .= "raw_content LONGTEXT not null,";
$querystr .= "formatted_content LONGTEXT not null,";
$querystr .= "primary key (id)";
$querystr .= ");";
$statement = $conn->prepare($querystr); <--- error here
$statement->bind_param("s", $title);
$statement->execute();
$statement->close();
答案 0 :(得分:2)
您不能将占位符用于表名,它只能用于代替表达式。所以CREATE TABLE ?
无效。使用:
$querystr = "CREATE TABLE `$title` (";
验证$title
是可接受的表名后。