MSSQL support for PHP with XAMPP

Armitage318
Armitage318 used Ask the Experts™
on
Hi,
I need to setup this kind of environment:
OS: Windows 7 professional 64bit
web server: Apache
database: SQL server 2008 (or even 2012)
lang: PHP 5.6.35

I need to provide PHP connection to SQL server.
I downloaded XAMPP from this url:

https://www.apachefriends.org/it/download.html

I noticed that PHP is compiled without SQL Server support :

(from phpinfo):
 "--without-mssql" "--without-pdo-mssql"

How can I solve my issue?
Thank you very much
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Gaurav SinghSolutions Architect

Commented:
you will need to buld PHP with MSSQL option
Refer below link it might help you.

https://help.directadmin.com/item.php?id=252

Commented:
You can use ODBC Connection

If you want to use this odbc so first of all you need to install odbc driver then create your connection dsn with mssql server

Download this https://www.microsoft.com/en-in/download/details.aspx?id=36434
 
Thank You

Author

Commented:
Hi, I used SQLSRV32 (according to my PHP version).
I extracted dll files in PHP extension dir, and I added to php.ini:

extension=php_sqlsrv_56_ts.dll
extension=php_pdo_sqlsrv_56_ts.dll

Open in new window


With this code:

<?php
 echo "<pre>";
 print_r(PDO::getAvailableDrivers());

Open in new window


I get:




Array
(
    [0] => mysql
    [1] => sqlite
    [2] => sqlsrv
)

Open in new window


anyway, when I try to use such library, I get error:

FATAL ERROR: cannot load modules!

Thank you
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Commented:
Restart your apache
check Your php and Apache version
Fixer of Problems
Most Valuable Expert 2014
Commented:
For the SQLSRV extension to work, you also need the OBDC driver or the SQL Native Client.  It won't work without it.

Author

Commented:
Hi,
should I use 32 bit or 64 bit of OBDC driver?
My OS is Windows 7 64 bit, but I noticed that PHP is compiled for 32 bit architecture.

Thank you

Author

Commented:
I am using a PHP script to test if mssql or sqlsrv PHP driver is present.
Script returns "FATAL ERROR: cannot load modules"

I see that related php code is:

if (function_exists("sqlsrv_connect")) _SQLLIB("MS",true);

if (function_exists("mssql_connect"))  _SQLLIB("TDS",true);

if (_SQLLIB()===false)
  DIE("FATAL ERROR: cannot load modules!");

Open in new window


I confirm that I do see PDO_SQLSRV in phpinfo.. it sounds strange to me that there is no sqlsrv_connect function available.
Thank you again

Author

Commented:
I founded this in Apache's log:

PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\\xampp\\php\\ext\\php_sqlsrv_56_ts.dl' - The specified procedure could not be found.\r\n in Unknown on line 0

Open in new window


I suspect that there is some mismatch in version.
I am using PHP version shipped with XAMPP (5.6.35); I don't know which version is PHP driver downloaded from Microsoft, they said only "5.6"


driver file: php_sqlsrv_56_ts.dll  , php_pdo_sqlsrv_56_ts.dll
PHP version: 5.6
Thread safe: yes
Use with PHP .dll: php5ts.dll

Open in new window



 

Thank you again..

Author

Commented:
Ok, I simpy renamed php_sqlsrv_56_ts.dl to php5ts.dll and now I get a different message:

Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => This extension requires the Microsoft ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712 [message] => This extension requires the Microsoft ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712 ) [1] => Array ( [0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft][Driver Manager ODBC] Nome origine dati non trovato e driver predefinito non specificato. [message] => [Microsoft][Driver Manager ODBC] Nome origine dati non trovato e driver predefinito non specificato. ) ) Could not connect to database: 1

Open in new window


So, Dave Baldwin was right, I need the OBDC driver ..
I will update you shortly

Author

Commented:
I also needed to rename php_sqlsrv_56_ts.dll to php5ts.dll in c:\xampp\php\ext

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial