ilkist Posted July 11, 2012 Share Posted July 11, 2012 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!! Quote Link to comment https://forums.phpfreaks.com/topic/265518-mssql-pdo-could-not-find-driver/ Share on other sites More sharing options...
ilkist Posted July 11, 2012 Author Share Posted July 11, 2012 **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... Quote Link to comment https://forums.phpfreaks.com/topic/265518-mssql-pdo-could-not-find-driver/#findComment-1360789 Share on other sites More sharing options...
ilkist Posted July 13, 2012 Author Share Posted July 13, 2012 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(); } Quote Link to comment https://forums.phpfreaks.com/topic/265518-mssql-pdo-could-not-find-driver/#findComment-1361301 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.