December 1st, 2009 • 12:12
Using PHP with SQL Azure
SQL Azure is a wonderful service running the database in the cloud. This post summarizes the gotchas that you might wanna lookout for when trying to connect your PHP applications to talk to SQL Azure.
- The default driver php_mssql.dll doesn’t work with SQL Azure. The Internets say that support for php_mssql is dropped from PHP 5.3. I have PHP 5.2.10 and was a bit surprised when I can connect to any SQL server instance in the network (2005/2008) using php_mssql but not to SQL Azure. The all too generic Unable to connect to server message was also not helping. You have to use the new MSSQL driver for PHP.
- After you download and unzip the new driver you’ll see a set of DLLs with different versions. For PHP 5.2.10 you have to use php_sqlsrv_52_ts_vc6.dll. Rename it as php_sqlsrv.dll and copy it to the <PHP>\ext directory.
- Then add
extension=php_sqlsrv.dllto your php.ini - After that, you have to connect to the SQL Azure database with MultipleActiveResultSets option turned off.
sqlsrv_connect( "server_name", array( "MultipleActiveResultSets" => 0, ... ) );
Voila! Now you’re all set to pull data from the clouds!
Leave a Reply
No Comment
Be the first to respond!