错误与绑定变量
问题描述:
我得到一个错误,在我写一份书面声明...错误与绑定变量
Number of elements in type definition string doesn't match number of bind variables on line 33. Create Topic Insert bind_param() failed:
我能想到的唯一的事情是因为NOW()
领域,但我认为这是不需要为此设置一个变量?
有没有什么我明显缺少在这个或什么可能会导致此错误?
//Prepared INSERT stmt for the forum topic
$stmt = $con->prepare("INSERT INTO forum_topics (`category_id`, `topic_title`, `topic_creator`, `topic_date`, `topic_reply_date`)
VALUES(?, ?, ?, NOW(), NOW())");
if (!$stmt || $con->error) {
die('Create Topic Insert prepare() failed: ' . htmlspecialchars($con->error));
}
if(!$stmt->bind_param('sssii', $cid, $title, $creator)) {
die('Create Topic Insert bind_param() failed: ' . htmlspecialchars($stmt->error));
}
if(!$stmt->execute()) {
die('Create Topic Insert execute() failed: ' . htmlspecialchars($stmt->error));
}
答
mysqli_stmt :: bind_param - mysqli_stmt_bind_param - 绑定变量来一份声明作为参数
因此,在你bind_param,你需要插入5个参数。
答
我解决了这个问题。我试图绑定NOW()
字段。我将代码行更改为..
if(!$stmt->bind_param('sssii', $cid, $title, $creator)) {
它现在完美工作。
U绑定3 ... sss – Drew