Reputation:
I'm using PHP Version 5.3.8 that was installed via XAMPP along with Microsoft SQL Server 2008 R2 (SQLEXPRESS). I have the drivers installed correctly (i guess) and have added the correct line into php.ini (extension=php_pdo_sqlsrv_53_ts_vc9.dll to be exact).
I'm trying to connect to the server like so:
try {
$DBH = new PDO("mssql:host=xxxx;dbname=xxxx", 'xxxx', 'xxxx');
} catch(PDOException $e) {
echo $e->getMessage();
}
I get the "could not find driver" error, and I've tweaked it all kinds of ways to solve the problem. I've tried all other kinds of drivers, but this is the only one that Apache doesn't give me an error on startup. When I run phpinfo(), the pdo_sqlsrv fields are all blank except pdo_sqlsrv.log_severity which is set to 0.
I DL'd my drivers from microsoft, and I've tried both 2.0 and 3.0
Any advice would be awesome!!
Upvotes: 11
Views: 55604
Reputation: 164
as I said in this please notice you must use the correct version of php_sqlsrv_xx_xts_xxx.dll and php_pdo_sqlsrv_xx_xts_xx.dll files.
for exmple if you use php version 7.4 and a 64 bit system and wamp you must download and use these files: php_sqlsrv_74_ts_x64.dll php_pdo_sqlsrv_74_ts_x64.dll for download you can use this site: https://go.microsoft.com/fwlink/?linkid=2152937 https://learn.microsoft.com/en-us/sql/connect/php/download-drivers-php-sql-server?view=sql-server-ver15
Upvotes: 0
Reputation: 492
Not sure if this is due to running a CentOS x86_64 machine but sqlsrv
didn't work as the 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();
}
Upvotes: 4
Reputation: 6469
mssql
is the old way of doing it, sqlsrv
should be more appropriate! In fact the extension is called (extension=php_pdo_sqlsrv_53_ts_vc9.dll) as well ;)
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
Upvotes: 8