PDO MSSQL Server - Driver not found

40,611

Solution 1

Alright. I suppose its just one of these days.

I got the wrong extension loaded from the supplied ones by MS. I needed to use php_pdo_sqlsrv_53_nts rather than php_sqlsrv_53_nts

Thanks for all the help

Solution 2

The PDO Extension is not the same as the native driver Microsoft is offering. For PDO you must enable

extension=php_pdo_mssql.dll

in your php.ini.

Normally this file (php_pdo_mssql.dll) should be in your PHP extension-directory (C:...\php\ext). If it's not there you can download PHP from http://windows.php.net/download/ and just take the extension from a package there (take one that correspond with your PHP version of course).

//edit: just read you latest comment. This extension is available for a very long time now and can be considered working. If you are not allowed to use it you must rewrite your code to use the functions the native driver offers for PHP.

Solution 3

Another possibility is to use the odbc drivers which are by default included in the php extensions, you still might have to uncomment them in your php.ini though.

extension=php_pdo_odbc.dll

Don't forget to restart your server afterwards ;-)

And then use it like this:

$db = new PDO('odbc:Driver={SQL Server};Server=192.168.x.x;Database=DatabaseName; Uid=User;Pwd=Password');
$stmt = $db->query("SELECT the_usual FROM aTable WHERE all='well'");
Share:
40,611
Richard
Author by

Richard

Updated on April 29, 2020

Comments

  • Richard
    Richard about 4 years

    I am currently trying to connect to my localdb on MSSQL 2012 Express.

    I have downloaded and installed the official microsoft driver from http://www.microsoft.com/en-us/download/details.aspx?id=20098

    I get some kind of SQLSRV section in my phpinfo(). But when I try to create a new PDO object it says it does not have the driver. Which I could understand since it is not mentioned on the phpinfo() PDO section, but it has its own section + the get_loaded_extensions also shows sqlsrv. I suppose thats from the official MS Driver ? I am using the php_sqlsrv_53_nts.dll With my Zend Server CE 5.6 with PHP 5.3.9

    Now as far as I understood I downloaded the wrong driver and should try the one that is brought by the PECL manager? There is only the sourcecode available and obviously I am on a windows machine so I can forget about everything that I need to compile myself - I am actually getting the suffix errors when using the powershell and my pecl / pear installation.

    Has anybody solve that problem ? Any help much appreciated

    All the best, Richard