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:
$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.
I have tried setting it using $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.
The PDO_DBLIB is an experimental extension and should not be used for production environments.
http://www.php.net/manual/en/ref.pdo-dblib.php
If you can, you should use PDO_SQLSRV instead:
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:
http://www.php.net/manual/en/ref.pdo-sqlsrv.connection.php
Let me know if that works for you
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.