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.
…. and did you figure it out how to connect the database?
Connecting was easy once I got the driver in place. I created a function with the connection info, then all I had to do to access it was call the function. Thanks for reminding me to follow up.
protected function _getRemoteConn()
{
$serverName = “your-server-name”;
$database = “db-name”;
$uid = ‘username’;
$pwd = ‘pw’;
try {
$con = new PDO(“sqlsrv:server=$serverName;Database = $database”, $uid, $pwd);
$con->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
print $e->getMessage();
}
return $con;
}
Great info.
I was able to connect to the server without any hassle, thumbs up