Jump to content

Recommended Posts

I'm using PHP Version 5.3.8 that was installed via XAMPP along with Microsoft SQL Server 2008 R2 (SQLEXPRESS). I have the drivers installed correctly (I think) and have added the correct line into php.ini (extension=php_pdo_sqlsrv_53_ts_vc9.dll to be exact). I'm trying to connect to the server like so:

try {
$DBH = new PDO("mssql:host=xxxx;dbname=xxxx", 'xxxx', 'xxxx');
}
catch(PDOException $e) {
echo $e->getMessage();
}

 

I get the "could not find driver" error, and I've tweaked it all kinds of ways to solve the problem. I've tried all other kinds of drivers, but this is the only one that Apache doesn't give me an error on startup. When I run phpinfo(), the pdo_sqlsrv fields are all blank except pdo_sqlsrv.log_severity which is set to 0.

 

I DL'd my drivers from http://www.microsoft.com/en-us/download/details.aspx?id=20098, and I've tried both 2.0 and 3.0

 

Any advice would be awesome!!

Link to comment
https://forums.phpfreaks.com/topic/265518-mssql-pdo-could-not-find-driver/
Share on other sites

**EDIT**

 

I just solved my own problem...

 

instead of

try {
$DBH = new PDO("mssql:host=xxxx;dbname=xxxx", 'xxxx', 'xxxx');
}
catch(PDOException $e) {
echo $e->getMessage();
}

 

I did

try {
$DBH = new PDO("sqlsrv:host=xxxx;dbname=xxxx", 'xxxx', 'xxxx');
}
catch(PDOException $e) {
echo $e->getMessage();
}

 

I was using the old method of connecting to the DB...

I don't want to confuse anyone, so here's a 100% working example of connecting to a MS SQL server using PDO. This method has detailed error reporting enabled.

 

$servername = "xxxxx";
$database = "xxxxx";
$user = "xxxxx";
$pass = "xxxxx";

try {
$DBH = new PDO('sqlsrv:Server='.$servername.';Database='.$database, $user, $pass);
$DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch(PDOException $e) {
echo $e->getMessage();
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.