简体   繁体   English

PDO:setAttribute()对dblib和SQL Server没有影响

[英]PDO: setAttribute() has no effect with dblib and SQL Server

I am connecting to an SQL Server database (SQL Server 2008 R2 SP2 x64) from a Linux server running PHP 5.3.19 using the following lines: 我使用以下行从运行PHP 5.3.19的Linux服务器连接到SQL Server数据库(SQL Server 2008 R2 SP2 x64):

$this->dbLink = new PDO(
    'dblib:host='.$this->host.';dbname='.$this->database,
    $this->user,
    $this->password,
    array(
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    )
);

The connection works perfectly fine, except that ATTR_ERRMODE works as ERRMODE_WARNING, no matter what I do. 连接工作完全正常,除了ATTR_ERRMODE用作ERRMODE_WARNING,无论我做什么。

I have tried setting it using $this->dbLink->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 我尝试使用$this->dbLink->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);设置它$this->dbLink->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); right before the query call, but it has no effect. 在查询调用之前,它没有任何效果。

If I use getAttribute() , I can confirm that PDO::ATTR_ERRMODE is indeed set to int(2) (ERRMODE_EXCEPTION), but I still get warnings and PHP keeps chugging along with obviously wrong queries. 如果我使用getAttribute() ,我可以确认PDO :: ATTR_ERRMODE确实设置为int(2) (ERRMODE_EXCEPTION),但我仍然收到警告,并且PHP一直伴随着明显错误的查询。

The PDO_DBLIB is an experimental extension and should not be used for production environments. PDO_DBLIB是实验性扩展,不应用于生产环境。

http://www.php.net/manual/en/ref.pdo-dblib.php http://www.php.net/manual/en/ref.pdo-dblib.php

If you can, you should use PDO_SQLSRV instead: 如果可以,您应该使用PDO_SQLSRV:

http://www.php.net/manual/en/ref.pdo-sqlsrv.php http://www.php.net/manual/en/ref.pdo-sqlsrv.php

Just change your connection setting from dblib: to the PDO_SQLSRV driver dns prefix sqlsrv: 只需将连接设置从dblib dblib:更改为PDO_SQLSRV驱动程序dns前缀sqlsrv:

http://www.php.net/manual/en/ref.pdo-sqlsrv.connection.php http://www.php.net/manual/en/ref.pdo-sqlsrv.connection.php

Let me know if that works for you 如果这对您有用,请告诉我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM