6

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

Richard
  • 1,543
  • 3
  • 25
  • 49
  • have you enabled pdo mssql in php.ini? – Leri Jun 28 '12 at 13:44
  • @PLB yes I have, before my `extension=php_sqlsrv_53_nts.dll` but it does not change. I have restarted my Apache several times as well. – Richard Jun 28 '12 at 13:52
  • But still take a look at [these steps](http://hk2.php.net/manual/en/pdo.installation.php) maybe you missed something. – Leri Jun 28 '12 at 13:54
  • @PLB thanks - the only thing that might be causing some trouble is that I do not load the php_pdo_mssql but this is experimental on the php.net and it we are advised to use the MS adapter :( – Richard Jun 28 '12 at 13:58
  • As my little research shows you can't use pdo to connect msserver without enabling `pdo_mssql.dll`. Maybe I could not search well. – Leri Jun 28 '12 at 14:08

3 Answers3

3

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.

Martin Müller
  • 2,565
  • 21
  • 32
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'");
Levite
  • 17,263
  • 8
  • 50
  • 50
0

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

Richard
  • 1,543
  • 3
  • 25
  • 49