Page 1 of 1

Unable to connect to mssql database using php file in XAMPP

PostPosted: 15. January 2015 08:55
by pavi_elex
I am facing a problem in XAMPP. I am using UBUNTU operating system (or sometimes CentOS). I have installed XAMPP 1.8.3-4 (before XAMPP 1.8.1 ) in both Operating systems (as /opt/lampp). I am not able to connect to mssql database using php file in any version of xampp.
I have written following code in a php file.
Code: Select all
<?php
try{
   $con = new PDO("dblib:dbname=dbname;host=hostname", 'username', 'password');
echo "Yes... Connected";
}catch(PDOException $e){
   echo 'Failed to connect to database: ' . $e->getMessage() . "\n";
   exit;
}
?>

I have saved this file as connection.php inside htdocs. Now when I run http://localhost/connection.php in browser
It gives me following error.
Code: Select all
Failed to connect to database: could not find driver

When I checked my phpinfo.php, I found the PDO driver "dblib" is missing under PDO module. Please see PDO section of XAMPP's phpinfo
Image
I think this is the problem that's why I am not able to connect to ms-sql database. I do not know, how to install dblib driver under pdo module.

We have installed individual apache, mysql, php, pgsql on another ubuntu system using command line (sudo apt-get install package-name) and we are able to connect to ms-sql database using same file.
The only difference between phpinfo of other ubuntu system and mine is the dblib PDO driver under PDO module. Other system has dblib driver but I do not have. Installing individual packages, php5-sybase gives dblib driver but I think this is missing in XAMPP.
This is the PDO section of other ubuntu system's phpinfo
Image

Please give me solution to connect to ms-sql database.

Thanks.

Re: Unable to connect to mssql database using php file in XA

PostPosted: 15. January 2015 09:50
by Beltran
XAMPP ships the mssql module but it does not include the PDO driver for MSSQL. We will check if we can enable it for next versions. Thanks for reporting it.