mauzilla
mauzilla

Reputation: 3592

PDO DBLib not working

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?

Upvotes: 1

Views: 6320

Answers (1)

Pondlife
Pondlife

Reputation: 16260

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

Upvotes: 4

Related Questions