共用方式為


Using the PHP Toolkit with ADO.NET Data Services

  1. Setup PHP on your windows machine
  2. Setup the PHP Toolkit
  3. Setting up the PHP samples on IIS
  4. Running the sample ADO.NET Data Services
  5. PHP Sample Applications Walkthrough

Setup PHP on your windows machine

The following steps show you how to setup your windows machine to host PHP applications.
We will be talking about hosting the only supported ( by MS Support ) PHP CGI application on IIS .

Using FastCGI to Host PHP Applications on IIS 7.0

  1. If you don’t find the php.ini-recommended file , then rename the php.ini-development file from your PHP folder.
  2. Once you are setup , if you get a HTTP 500 internal server error when browsing to the Php.ini file ,
    then you need setup your timezone in the PHP.ini file .
  3. To do this , find the line in the php.ini file “date.timezone” .
  4. If it has a semi-colon before it , remove it .
  5. Set the date.timezone’s  value to be a valid value from this list : List of Supported Timezones

In my php.ini , I have set the value to be date.timezone = "America/Los_Angeles"

Setup the PHP Toolkit

Follow the instructions on the codeplex site to setup your machine.
Installation and Configuration

Setting up the PHP samples on IIS

I have copied the phpsamples folder from the downloaded phpdataservices1.0 folder
into the %SystemDrive%\inetpub\wwwroot folder.This is just so that I dont need to configure any permissions
for the IIS accounts.
Open the IIS manager by running “INETMGR” from the “run” prompt on the start menu

Select the PHPSamples folder from the “Default Web Site”
Samples_Not_Application

Right-Click the Virtual directory and select “Convert to Application”
Samples_To_Application

Confirm creating the virtual directory by  pressing “OK” in the next dialog that turns up
Samples_To_Application_Confirm

This sets up the PHP applications that access the ADO.NET Data Service,
We still need to setup the actual Data Services that the PHP Samples access.

Running the sample  ADO.NET Data Services

Find the ADODotNetDataServices folder in the PHPDataServices1.0 download.
This should be under the “samples” directory.
i.e PHPDataServices1.0\samples\ADODotNetDataServices

Setup the Databases required for the project to run

1) Unzip the zipped database files from the

PHPDataServices1.0\samples\ADODotNetDataServices\data folder.
2)   Open up SQL management studio and Connect to your Database server
3) Right–click the databases node and select “Attach…”

Attach_DB_Step_1

4) In the “Attach Database” dialog , press “Add” and select the unzipped “VideoGameStore_Data.mdf” file.
You will notice that once you select the MDF file  , the dialog will complain about a missing .ldf file.
5) This is a routine warning , select the ldf file row in the dialog and press “Remove”
 Attach_DB_Step_2

For the other database Northwind, you can use the sample database that are available from Download.Microsoft.com
Here’s a link to download the Northwind sample database : Northwind and pubs Sample Databases for SQL Server 2000
Installation should be straight-forward as it comes with an MSI that is supposed to setup the database for you.

Disclaimer : I already had a copy of the Northwind database on my machine and didn’t use the installer above.
 
Once you have your databases setup , modify the respective connection strings web.config file from the ADODotNetDataServices project.

 <connectionStrings>
    <add name="NorthwindEntities" 
         connectionString="metadata=res://*/NorthwindModel.csdl|res://*/NorthwindModel.ssdl|res://*/NorthwindModel.msl;
                           provider=System.Data.SqlClient;
                           provider connection string=&quot;YOURCONNECTIONSTRINGHERE&quot;" 
         providerName="System.Data.EntityClient" />
    <add name="VideoGameStoreEntities" 
         connectionString="metadata=res://*/VideoGameStoreModel.csdl|res://*/VideoGameStoreModel.ssdl|res://*/VideoGameStoreModel.msl;
                           provider=System.Data.SqlClient;
                           provider connection string=&quot;YOURCONNECTIONSTRINGHERE & quot;" 
         providerName="System.Data.EntityClient" />
</connectionStrings>
  1. Once you have the database and the Data Service setup, then configure the project to only run on the URL that the PHP Samples expect to find the Data Service on.

    To do this :

    In Visual Studio,Go to the properties of the Project.

  2. Click on the “Web” Tab in the left-hand pane.

  3. Under the “Servers” section , Select the “Specific Port”  option and enter “8080” for the port number.

    Setup_DataService_Select_Port

  4. Now, run the project in Visual studio and launch the PHP samples by browsing to the Index.php page

    in the PHPSamples virtual directory.

PHP Sample Applications Walkthrough

You should see this as the startup page when you run the PHP Samples

PHP_SAMPles_Screen1

Demo tab contents

PHP_SAMPles_Screen_Samples1

Select the ADO.NET Data Services Editor Sample to see some pure PHP awesomeness

PHP_SAMPles_Screen2

Here’s an editor page for the Customers Entity Set:

Customers_Edit_Screen

See that little text box over there ?

Yeah , it allows me to enter the Astoria URI operators like top , skip , filter to filter the rows bound to the grid below.

The gird is editable too , Clicking on the “Detail” link in the first column of the grid brings up an editor for the customers

entity that was selected.

Customers_Edit_Screen_2

So , there you have it , instructions to setup the samples and some tours of the sample applications.

Since I know next to nothing about PHP , I have a few questions for our PHP-Savvy users.

  1. Which application framework(s) do you use  to build PHP applications? I know about CAKE and ZEND , any others?
  2. Do you use a specific Validation framework or do you use the one that came with the  application framework?