PHP mssql_query 不能使用双引号
在 java-jdbc 中,我可以轻松运行以下 SQL(注意列和表名称周围的双引号),
Select
cus."customer_id" ,
cus."organisation_or_person" ,
cus."organisation_name" ,
cus."first_name" ,
cus."last_name" ,
cus."date_became_customer" ,
cus."other_customer_details"
From
"Contact_Management"."dbo"."Customers" cus
但 PHP 中的相同查询会出错,提示无效语法
“警告:mssql_query() [function.mssql-query]:消息: 'customer_id' 附近的语法不正确(严重性 15)”
但如果删除所有双引号,查询将正常工作并且不会出现错误。
该查询是从 java 应用程序移植的,因此我想保留双引号和 SQL 原样。还有其他解决方案吗?
谢谢 Nilesh
Volkerk -- 解决方案(SET QUOTED_IDENTIFIER ON)
我执行了以下操作
$sql = <<<EOD
Select
cus."customer_id" ,
cus."organisation_or_person" ,
cus."organisation_name" ,
cus."first_name" ,
cus."last_name" ,
cus."date_became_customer" ,
cus."other_customer_details"
From
"Contact_Management"."dbo"."Customers" cus
EOD;
$db->Execute('SET QUOTED_IDENTIFIER ON');
$rs = $db->Execute($sql);
,效果非常好,
非常感谢..
In java-jdbc, I can easily run the following SQL (NOTE the double quotes around columns and table names)
Select
cus."customer_id" ,
cus."organisation_or_person" ,
cus."organisation_name" ,
cus."first_name" ,
cus."last_name" ,
cus."date_became_customer" ,
cus."other_customer_details"
From
"Contact_Management"."dbo"."Customers" cus
But the same query in PHP errors out saying invalid syntax
"Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 'customer_id'. (severity 15) "
But If remove all the double quotes, the query works fine and no errors.
The query is ported from a java application so I would like to keep the double quotes and the SQL as it is. Any alternative solutions?
Thank you
Nilesh
Volkerk -- Solution (SET QUOTED_IDENTIFIER ON)
I did the following
$sql = <<<EOD
Select
cus."customer_id" ,
cus."organisation_or_person" ,
cus."organisation_name" ,
cus."first_name" ,
cus."last_name" ,
cus."date_became_customer" ,
cus."other_customer_details"
From
"Contact_Management"."dbo"."Customers" cus
EOD;
$db->Execute('SET QUOTED_IDENTIFIER ON');
$rs = $db->Execute($sql);
And it worked perfect
Thank you so much..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
QUOTED_IDENTIFIER
可能设置为 OFF。http://msdn.microsoft.com/en-us/library/ms174393。 aspx 说:
将其设置为“打开”,然后就可以开始了。
QUOTED_IDENTIFIER
is probably set to OFF.http://msdn.microsoft.com/en-us/library/ms174393.aspx says:
set it to
On
and you're good to go.它并不完全按原样,但您可以用反引号替换双引号
"
:It's not exactly as-is, but you could replace the double-quotes
"
with backticks:这又如何呢?
What about this?