Host Wordpress on Windows Azure: Consume SQL Azure Using PHP

our wordpress live sample website:

https://wordpress-win-azure.cloudapp.net/

 

 Download sample project here

 

This tutorial article will show you how to consume SQL Azure using PHP with just several easy steps.  Please refer first series article Run PHP application in Windows Azure for a prerequisite.

 

1. To enable PHP to access SQL Azure, SQL Server Driver must be added to PHP extensions. (For SQL Azure is built on SQL Server).Download it form SQL Server Driver for PHP 2.0.

2.Open and extract it, driver files are listed below.

 

We choose php_sqlsrv_53_nts_vc9.dll, for it matches our PHP version, VC9 x86 Non Thread Safe.

Put the driver into php\ext folder in the PHP _WebCgiRole project.

Rename php.ini-develop in the php folderto php-ini. Right click on php.ini, choose Properties, and change the value of Build Action to Content.

Click to Open php.ini, look up extension_dir and change its value to "./ext" . It indicates the extension directory of PHP.

 

Add "extension = php_sqlsrv_53_nts_vc9.dll "to php.ini.

 

4. Put the PHP code below to index.php (refer to Run PHP application in Windows Azure ) .Please refer to here  to replace the SQL Azure account information with yours.

 

 

<?php

$serverName = "tcp:ServerID.database.windows.net, 1433";

$connectionOptions = array("Database" => "yourdatabase",

"UID" => "yourusername@ServerID",

"PWD" => "yourpassword",

);

$retry = 10;

$conn ;

while($retry--)

{

  $conn = sqlsrv_connect($serverName, $connectionOptions);

  if($conn)

  {

    echo "Connect Success!";

    break;

  }

}

if($conn === false)

{

   die(print_r(sqlsrv_errors(), true));

}

?>

 

 

 

 

 

 

 

Verification:

5. Press F5 to debug the application, wait for the browser to start, you'll see the result below:

 

 

 

 

 

You can put it into Windows Azure Hosted service now, and will get the same result.

The process is still simple and easy as before, now you can exploit the power of SQL Azure!

 

References:

https://msdn.microsoft.com/en-us/library/ff394110.aspx

https://blogs.msdn.com/b/brian_swan/archive/2010/02/12/getting-started-with-php-and-sql-azure.aspx

https://channel9.msdn.com/learn/courses/Azure/SQLAzure/IntroToSQLAzure/Exercise-1-Preparing-Your-SQL-Azure-Account/

 

 

 

 

 

 

 

Topic

Description

Chapter 1: Using PHP application in Windows Azure

This article will show how easy to run PHP application inWindows Azure

Chapter 2: Consume SQL Azure Using PHP

This article describes how to access SQL Azure using PHP.

Chapter 3: Host Wordpress on Windows Azure

This article describes the process about host Wordpress on Windows Azure. Similarly, you will see how easy it will be.

Chapter 4: Using Windows Azure Storage in Wordpress

This article introduces the Windows Azure Storage plugin for WordPress . It enables Wordpress store multimedia contenton Windows Azure Storage.