PHP-由mysqli_stmt_bind_param创建的返回语句
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHP-由mysqli_stmt_bind_param创建的返回语句,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1678字,纯文字阅读大概需要3分钟。
内容图文
我正在使用mysqli_stmt_bind_param()创建INSERT语句.由于某种原因,我遇到了错误.我使用mysqli_error()查看错误消息,但这并不是特别有用.
有没有一种方法可以查看实际正在执行什么查询?
产生的错误:
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 ‘desc,date,expdate,mintix,maxtix,contactname,contactemail,contactphone) VALUES (?’ at line 1
解决方法:
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);
内容总结
以上是互联网集市为您收集整理的PHP-由mysqli_stmt_bind_param创建的返回语句全部内容,希望文章能够帮你解决PHP-由mysqli_stmt_bind_param创建的返回语句所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。