PHP 字符串不喜欢多个变量插入吗?
我使用 PHP 5.2 和 Oracle 数据库 11.1。
该代码
$query = oci_parse($conn, "SELECT * FROM COMMENTS WHERE PINID=$pinID and COMMENTID=$commentID");
导致此错误:
警告:oci_execute() [function.oci-execute]:ORA-00904:“COMMENTS”:C:\IODwww\hello.php 中的标识符无效第159行
^
但是运行它可以正常工作:
$query = oci_parse($conn, "SELECT * FROM COMMENTS WHERE PINID=$pinID and COMMENTID=1");
这是我将多个变量注入查询字符串的结果,还是我犯了其他错误?
I'm using PHP 5.2 with Oracle Database 11.1.
The code
$query = oci_parse($conn, "SELECT * FROM COMMENTS WHERE PINID=$pinID and COMMENTID=$commentID");
results in this error:
Warning: oci_execute() [function.oci-execute]: ORA-00904: "COMMENTS": invalid identifier in C:\IODwww\hello.php on line 159
^
But running this works fine:
$query = oci_parse($conn, "SELECT * FROM COMMENTS WHERE PINID=$pinID and COMMENTID=1");
Is this a result of me injecting multiple variables into the query string, or am I making some other mistake?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
出于性能和 SQL 注入的原因,您应该使用 占位符变量,如下所示:
For both performance and SQL Injection reasons, you should be using placeholder variables, like so:
oci_execute()
的警告不是 PHP 警告。结果查询有问题。将其打印出来并查看一下。
oci_execute()
's warning is not a PHP warning. There is something wrong with the resulting query.Print it out and take a look at it.
PHP 字符串中的多个变量没有问题。
要调试问题,您可以尝试:
并查看输出是否真正匹配:
我唯一能想到的是 commentID 为空或包含“\n”或附加的导致错误的内容。
如果与
=1
一起使用,数据库发出的错误代码“输入的列名丢失或无效。”对我来说没有多大意义。There is no problem with multiple variables in a PHP string.
To debug the problem, you can try:
and see if the output really matches:
The only things I can think of is that commentID is empty or contains a "\n" or something attached to it that causes the error.
The errorcode the database puts out, "The column name entered is either missing or invalid.", doesn't make much sense to me if works with
=1
.尝试将变量放在括号内:
还要确保
$commentID
不会返回空白值,否则会在末尾留下COMMENTID=
并在尝试时导致错误运行查询。Try to put the variables within brackets:
Also make sure that
$commentID
is not returning a blank value which would leave justCOMMENTID=
at the end and would cause an error when trying to run the query.