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
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
Please give me solution to connect to ms-sql database.
Thanks.