A new bridge for PHP developers to .NET through REST: Toolkit for PHP with ADO.NET Data Services

[Update - March 16, 2010: the toolkit is now called "OData SDK for PHP", and "ADO.NET Data Services" is now called "WCF Data Services". Check related posts on OData ]  

Today, I’m excited to announce that we are releasing a new project that bridges PHP and.NET.
More precisely, we are releasing today the Toolkit for PHP with ADO.NET Data Services which makes it easier for PHP developers to take advantage of ADO.NET Data Services, a set of features recently added to the .NET Framework. ADO.NET Data Services offer a simple way to expose any sort of data in a RESTful way. The Toolkit for PHP with ADO.NET Data Services is an open source project funded by Microsoft and developed by Persistent Systems Ltd. and is available today on Codeplex: phpdataservices.codeplex.com

You can see an overview and quick demo of the toolkit in the following Channel9 video with Pablo Castro (software architect of ADO.NET Data Services) and me:

Get Microsoft Silverlight

A little bit more about ADO.NET Data Services

ADO.NET Data Services (formerly known as Project “Astoria”) is a technology used to expose a wide range of data sources through a RESTful service interface. Data sources can be relational databases, XML files, and so on. ADO.NET Data Services defines a flexible addressing and query interface using a URL convention, as well as the usual resource manipulation methods on data sources (it supports the full range of Create/Read/Update/Delete operations).

There is full support for ADO.NET Data Services in Visual Studio 2008 SP1 as well as in the upcoming Visual Studio 2010; this includes direct support for both creating and consuming data services directly from the development environment. You can find more information about ADO.NET Data Services here, (I recommend the “How do I… ” videos).

Architecture of the Toolkit for PHP with ADO.NET Data Services

You should consider two aspects of the PHP Toolkit:

  • At design time: the PHP Toolkit generates proxy classes based on the metadata exposed by the ADO.NET Data Services (built with Visual Studio, including Express editions).
  • At run time: you call from your code the PHP proxy classes, so that you can easily program against the ADO.NET Data Service using a set of local PHP classes that represent the structure of the remote data. Using RESTful services over HTTP, the communication between the PHP application and ADO.NET Data Services is taken care of by the PHP proxy classes and the Toolkit libraries, but of course you can look at (or edit) this code.

PHP_ADO_DATA_SERVICEArchitecture

Running the Toolkit for PHP with ADO.NET Data Services step by step

In the following steps we assume that you have already created the ADO.NET Data Services on top of the Northwind sample SQL Server database (check this “How do I…” video). The service I created exposes data like this, through a simple URL:

PHP_ADO_DATA_SERVICE_Schema

The next step is to use the PHPDataSvcUtil.php utility that is part of the toolkit, and point it to the URL of the Data Service. It will read the Data Service metadata and create the PHP proxy classes (called northwinddb.php in our example):

PHP_ADO_DATA_SERVICE_Commandline

The code generated (northwinddb.php) looks like this:

PHP_ADO_DATA_SERVICE_CodeGen

At runtime, you simply include in your code the northwinddb.php files and the URL of the data service:

PHP_ADO_DATA_SERVICE_Codehead

And then you can start writing your PHP code to access the data collections. Note the first highlighted line: it defines the query over the data service. Many options are available, the full description of the query format can be found here.

PHP_ADO_DATA_SERVICE_CodeCore

And here is the result:

PHP_ADO_DATA_SERVICE_Result

I hope you enjoy reading this quick introduction to the Toolkit for PHP with ADO.NET Data Services.
Feel free to check the project site on Codeplex phpadodataservices.codeplex.com. As always your feedback is welcomed!

Claudio Caldato, Senior Program Manager,
Interoperability Technical Strategy team.