由mysqli_prepare()创建的准备语句是服务器端准备好的语句。
当你执行这样一个准备好的语句时,只传输语句ID和参数,而不是某些查询字符串,就像你用实际参数(客户端,即你的PHP脚本)替换占位符一样。
但是你可以看到的结果在MySQL服务器的通用日志,看到Prepared Statement Logging
编辑:你的情况,因为desc
是保留关键字声明的准备失败。
有关关键字的列表以及如何使用它们作为标识符(如果需要的话)看到http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
$q = '
INSERT INTO
`event`
(
`cityid`, `name`, `desc`, `date`,
`expdate`, `mintix`, `maxtix`,
`contactname`, `contactemail`, `contactphone`
)
VALUES
(
?,?,?,?,
?,?,?,
?,?,?
)
';
if (false===($stmt=mysqli_prepare($dblink, $q))) {
/*
in production-code you might not want to reveal
the error string to each and every user
...but for this example and for debugging purposes:
*/
die('mysqli_prepare failed: '.htmlspecialchars(mysqli_error($dblink)));
}
$rc = mysqli_stmt_bind_param(
$stmt,
"issssiisss",
$city,$name,$desc,$date,
$expdate,$mintix,$maxtix,
$contactname,$contactemail,$contactphone
);
if (false===$rc) {
die('mysqli_stmt_bind_param failed: '.htmlspecialchars(mysqli_stmt_error($stmt)));
}
if (false===mysqli_stmt_execute($stmt)) {
die('mysqli_stmt_execute failed: '.htmlspecialchars(mysqli_stmt_error($stmt)));
}
mysqli_stmt_close($stmt);
请告诉我们你的代码。否则很难帮助你。 – 2010-03-28 00:13:00
除了byronh评论之外,您还应该能够将查询语句存储在变量中,然后{query,echo,save}查询语句和错误代码。 – bdl 2010-03-28 00:14:33
@bdl我无法找到一种方法将准备好的语句转换回字符串(我认为bigmac所要求的是什么)。 – 2010-03-28 00:15:45