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
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, …
connect string may be something like this (in /app/config/main.php):
I have tried removing the non-PDO driver, but still not working.
I have created a username/password to the server PCNAME\SQLEXPRESS and am able to login using SQL management studio
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??
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
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: