6

I wanted to setup a database connection from PHP to SQL server 2012.I have a wamp server(64 bit) set up on a windows machine(64 bit) with PHP 5.5.12 and on the same machine I have SQL server 2012 installed.

Extracted sqlsrv drivers from official_link

Copied the extracted drivers php_sqlsrv_55_ts.dll, extension = php_pdo_sqlsrv_55_ts.dll to php\ext folder, and then changed the php.ini file to include the extensions

extension = php_sqlsrv_55_ts.dll; extension = php_pdo_sqlsrv_55_ts.dll;

Now I tried

<?php
  phpinfo();
 ?>

I see the following information without any SQL server information in it.

enter image description here

enter image description here

Don't seem to have configured SQL server connection successfully. Could some one please guide me on what I am missing here.

Braiam
  • 1
  • 11
  • 47
  • 78
user2569524
  • 1,651
  • 7
  • 32
  • 57
  • Did you restart all services and maybe even rebooted after making the changes? If not, do. – Funk Forty Niner Nov 19 '14 at 03:36
  • Yes I restarted all the services. – user2569524 Nov 19 '14 at 03:42
  • Have you also download and installed the `Microsoft SQL Server 2012 Native Client` and `Microsoft ODBC Driver 11`. Remember the php extensions do not talk directly to the database, they talk to the Native Client. See the `System Requirements` section on the download page you reference above. – RiggsFolly Nov 19 '14 at 09:21
  • @RiggsFolly I have complete SQL server installed on the same machine, so I already have 'Microsoft SQL Server 2012 Native Client' installed by default that came with sql server installation. I checked ODBC administrator to confirm. – user2569524 Nov 19 '14 at 19:10
  • Can you try executing the php.exe from a command prompt. It may give you additional error output that you cannot see on the web. – Franklin P Strube Dec 07 '14 at 20:16
  • sorry if im wrong (i dont use mssql) but is this an simple extension or a zend extension? – UnskilledFreak Dec 09 '14 at 14:40
  • You have to compile php from source. with "--with-mssql" option. since pecl does not support any pdo/mssql/sybase extension on windows. http://windows.php.net/downloads/pecl/releases/ – risyasin Dec 10 '14 at 21:24
  • try non thread safe version of sql driver for php. also if you can try 32bit version of wamp with sql server driver i had a terrible experience with 64bit wamp and mssql ;) – KTYP Dec 12 '14 at 17:04
  • clear wamp's logs , and restart wamp, read log , it's must contain a error ,that explain why dll not loaded! – Pouya Darabi Dec 12 '14 at 19:55

3 Answers3

4

64 bit WAMP server was not able to connect using the drivers extension = php_sqlsrv_55_ts.dll; extension = php_pdo_sqlsrv_55_ts.dll;

So, I installed a 32 bit version of the WAMP server and it works fine now.

user2569524
  • 1,651
  • 7
  • 32
  • 57
3

Check the php error log (c:\wamp\logs\php_error.log). I had the same setup (64bit WAMP/PHP 5.5.12) and same missing sqlsrv reference in phpinfo and I got this error in my log:

PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.5.12/ext/php_pdo_sqlsrv_55_ts.dll' - %1 is not a valid Win32 application. in Unknown on line 0

The solution was to install the 64bit version of the sqlsrv drivers. I found the unofficial 64bit drivers through http://robsphp.blogspot.nl/2012/06/unofficial-microsoft-sql-server-driver.html

Warning: In my testing I found these 64bit PHP_PDO_SQLSRV extension 10 times slower than when using PHP_PDO_ODBC.

Jan
  • 2,165
  • 1
  • 18
  • 13
0

I am visiting this thread and i think this might help full for you and other with the same issue: How can I install pdo_sqlsrv on my windows 2008 Server 2008 R2?

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)}.

Above is taken from PDO MSSQL Server - Driver not found read for more details. i have the same issue foe linux and i have saved all the pages thats why i am quoting for you help.

if all above didn't work for you then:


On the php.net it is listed that

On Windows, PDO_ODBC is built into the PHP core by default. It is linked against the Windows ODBC Driver Manager so that PHP can connect to any database cataloged as a System DSN, and is the recommended driver for connecting to Microsoft SQL Server databases. http://php.net/manual/en/ref.pdo-odbc.php

You can connect to mssql server using odbc drivers as i have never connect by my self from windows i use to do it through linux using freeTds, following pages might help you

  1. http://craigballinger.com/blog/2011/08/usin-php-5-3-with-mssql-pdo-on-windows/
  2. Connect PHP to MSSQL via PDO ODBC
  3. PHP to SQL Server without ODBC or MSSQL support
Community
  • 1
  • 1
saqibahmad
  • 962
  • 1
  • 9
  • 18