Connect to SQL Server using PDO

#3927353 – Pastie.

How to connect to SQL Server using PDO

try {
      $con = new PDO( "sqlsrv:server=$serverName;Database = $database", $uid, $pwd); 
      $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); 
   }

   catch( PDOException $e ) {
      die( "Error connecting to SQL Server" ); 
   }

SQL Server, XAMPP 1.7.7, PHP 5.3

Apache Friends Support Forum • View topic – SQLSRV and XAMPP 1.7.7 [SOLVED].

Who should read this?

Those who need to connect to a MS SQL Server database from PHP 5.3.

Why?

Because the vanilla install of PHP will not get you where you need to be. Trust me, I just spent the last two hours trying to figure this out.

What should I do (excerpted from above link)?

I just tried it to see if I could add them without crashing Apache and it started up fine.

1. I grabbed the PHP drivers from here: http://www.microsoft.com/download/en/de … n&id=20098
2. I extracted that package into a folder on my desktop
3. I copied “php_pdo_sqlsrv_53_ts_vc9.dll” and “php_sqlsrv_53_ts_vc9.dll” to my “/xampp/php/ext” folder
4. Added the extension lines to my “php.ini” file
5. Updated the [latest] Microsoft SQL Client on my machine [v 2012 as of this writing] (Stated as a requirement on the PHP manual page)
6. Started Apache via the Control Panel and it started up without crashing

Caveat: This process only got me to where I could start Apache without crashing. I still need to figure out how to connect to the database. Stay tuned.