PDO DBLib无法正常工作 [英] PDO DBLib not working
问题描述
我与DBLIB PDO驱动程序建立了连接,并且连接时没有出现任何错误,但是当我运行查询时,抛出了异常,并出现以下错误.我也玩过查询的语法.我正在连接到MS SQL服务器:
SQLSTATE[HY000]: General error: 208 General SQL Server error: Check messages from the SQL Server [208] (severity 16) [SELECT PCO_INBOUNDLOG.PHONE FROM PCO_INBOUNDLOG]
代码:
$sql = "SELECT PCO_INBOUNDLOG.PHONE FROM PCO_INBOUNDLOG";
foreach($this->mssql->query($sql) as $row) {
print_r($row);
}
这是我第一次对MS SQL服务器进行查询,因此我的语法可能是错误的,有什么主意吗?
首先,找出错误208的含义:
select * from sys.messages where message_id = 208
第三,正确编写查询:
SELECT PHONE FROM PCO_INBOUNDLOG
或者,可能更好(因为包括模式名称是一个好习惯):
SELECT PHONE FROM dbo.PCO_INBOUNDLOG
甚至:
SELECT p.PHONE FROM dbo.PCO_INBOUNDLOG p
I have a connection with the DBLIB PDO driver, and I am not getting any errors on connecting, but when I run a query an exception is thrown with the error below. I have played around with the syntax of the query as well. I am connecting to a MS SQL server:
SQLSTATE[HY000]: General error: 208 General SQL Server error: Check messages from the SQL Server [208] (severity 16) [SELECT PCO_INBOUNDLOG.PHONE FROM PCO_INBOUNDLOG]
The code:
$sql = "SELECT PCO_INBOUNDLOG.PHONE FROM PCO_INBOUNDLOG";
foreach($this->mssql->query($sql) as $row) {
print_r($row);
}
This is the first time I have ever done a query to a MS SQL server so my syntax may be wrong, any ideas?
First, find out what error 208 means:
select * from sys.messages where message_id = 208
Second, check the FROM syntax (including the examples!) and object identifier rules.
Third, write the query correctly:
SELECT PHONE FROM PCO_INBOUNDLOG
Or, probably better (because it's good practice to include the schema name):
SELECT PHONE FROM dbo.PCO_INBOUNDLOG
Or even:
SELECT p.PHONE FROM dbo.PCO_INBOUNDLOG p
这篇关于PDO DBLib无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!