MSSQL PDO could not find driver

I am using the PHP version 5.3.8, which was installed via XAMPP along with Microsoft SQL Server 2008 R2 (SQLEXPRESS). I installed the drivers correctly (I think) and added the correct line to php.ini (extension = php_pdo_sqlsrv_53_ts_vc9.dll, to be precise).

I am trying to connect to the server like this:

try { $DBH = new PDO("mssql:host=xxxx;dbname=xxxx", 'xxxx', 'xxxx'); } catch(PDOException $e) { echo $e->getMessage(); } 

I get a โ€œcan't find driverโ€ error, and I reworked all sorts of ways to solve the problem. I tried all other types of drivers, but this is the only one that Apache does not give me an error on startup. When I run phpinfo (), the pdo_sqlsrv fields are empty except for pdo_sqlsrv.log_severity, which is set to 0.

I DL'd my drivers from microsoft , and I tried both 2.0 and 3.0

Any advice would be awesome !!

+6
source share
2 answers

mssql is an old way to do this, sqlsrv should be more appropriate! In fact, the extension is called (extension = php_pdo_ sqlsrv _53_ts_vc9.dll);)

 try { $DBH = new PDO("sqlsrv:Server=xxxx;Database=xxxx", 'xxxx', 'xxxx'); } catch (PDOException $e) { echo $e->getMessage(); } 

Hope this helps!

Source: http://php.net/manual/fr/ref.pdo-sqlsrv.connection.php

examples from the documentation

+5
source

Not sure if this is related to starting the CentOS x86_64 machine, but sqlsrv did not work as a driver for me, I had to use dblib :

 try { $DBH = new PDO("dblib:host=xxxx;dbname=xxxx", 'xxxx', 'xxxx'); } catch (PDOException $e) { echo $e->getMessage(); } 

Source and thanks: http://grover.open2space.com/content/use-php-and-pdo-connect-ms-sql-server

+2
source

Source: https://habr.com/ru/post/944010/


All Articles