PDO DBLib无法正常工作 [英] PDO DBLib not working

查看:90
本文介绍了PDO DBLib无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与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

第二,检查 FROM语法(包括示例!)和对象标识符规则.

第三,正确编写查询:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆