Could Not Find Driver Sqlsrv

I am using WAMP on Windows 7 and want to use MSSQL instead of MYSQL. I have therefore enabled the extensions php_mssql and php_pdo_mssql and restarted all services. I have double checked in the php.ini file and these extensions are enabled there as well. When using the following connection string as used in the documentation it is not working:

I looked around a bit and it seems like using SQLSRV is better and therefore downloaded the php_sqlsrv.dll and php_pdo_sqlsrv.dll to the extensions folder. Then I added the following lines to php.ini and restarted all services.

Together with this I am also using a different connection string which looks like this:

But I still get the same error message: CDbConnection failed to open the DB connection…could not find driver

Can you please help me out? I am using PHP 5.3.0 and Apache 2.2.11

Using MSSQL with PHP may be tricky.

  1. You should not combine more PHP drivers - you only need "PDO_SQLSRV"

(Yii only supports pdo_* family drivers).

(also see http://www.synet.sk/php/en/230-php-drivers-for-microsoft-sql-server-mssql-sqlsrv-utf8)

  1. You must have correct MSSQL Server (or MSSQL Express) installation and have created PHP user (you must know username + password) with configured access (read/write) to target database. Also you must know how you connect - via pipes, …

  2. connect string may be something like this (in /app/config/main.php):


'db'=>array(

    'connectionString' => 'sqlsrv:server=HOMEPC\\SQLEXPRESS;database=myDB01;MultipleActiveResultSets=false',

    'username' => 'sa',

    'password' => 'sapass',

),

where sa/sapass is existing MSSQL user with granted access to your database "myDB01".

  1. I have tried removing the non-PDO driver, but still not working.

  2. I have created a username/password to the server PCNAME\SQLEXPRESS and am able to login using SQL management studio

  3. I have tried with that connectionString, but it does not work still. The user already has access to the db.

Could it be that I have the wrong version of the pdo_sqlsrv.dll? I downloaded the one from the Microsoft website. This is working on another server for me with Yii and SQLSRV. Any ideas what I am doing wrong here??

I have been using SQL Server with Yii for a long time now.

Here is my connection string:




return array(

                    'class'=>'CDbConnection',

                    'connectionString' => 'sqlsrv:Server=192.168.0.1;Database=mysecretdatabase',

                    'username' => 'sa',

                    'password' => 'password',

                    'charset' => 'GB2312',

                    'tablePrefix' => '',

                    'enableProfiling'=>true,

                    'enableParamLogging'=>true,

                );



A few things that might be wrong:

The latest Microsoft drivers (SQLSRV30) can only be used with SQL Server 2005 and newer.

The files you downloaded from Microsoft should have the driver names as such (php_pdo_sqlsrv_53_ts.dll). You need to make sure that you’re using the correct version. The 53 would be your php version and then you need to figure out if you’re using the thread safe or not thread safe version of PHP, which would be the nt or nts suffix in the driver name. You can find this info by looking at your PHP info and looking for “Thread Safety.” It will either be enabled or disabled.

If you are using the SQLSRV20 driver there are also two versions, one compiled with VC6 and the other compiled with VC9. This also has to match your PHP instance. If you look at your PHP info this will be near the top after "Compiler" You should see something that looks like "MSVC9 (Visual C++ 2008)."

Lastly, I sometimes put the full path to the driver in the php.ini.


; PDO MS SQL

extension="C:/php/ext/php_sqlsrv_53_ts_vc9.dll"

extension="C:/php/ext/php_pdo_sqlsrv_53_ts_vc9.dll"

Downloads:

http://www.microsoft.com/en-us/download/details.aspx?id=20098

Thank you Ryan Z! Excellent answer. I was using the vc9 driver file, while the phpinfo showed that it should be vc6. So all I did was to add the vc6 file into the extension directory and add the following row:

:)