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.


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:


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):


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


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


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.


And here is the 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.

Comments (11)

  1. Phillip Jain says:

    This is disappointing… with 0.1% of the PHP codebase on Windows or SQL Server .. do these “Interoperability” engineers think forcing us to REWRITE everything for their weird APIs …

    Microsoft should have got developer feedback. We cooperated in market research for IBM and found their approach using PDO MUCH more reasonable.

    Hubris is not good and this is not specific to Microsoft. Another example is Google wanting developers to rewrite everything for AppEngine.

    — Pradeep Jain

  2. yop says:

    Well, this is about interoperability (heterogeneous systems, one .NET, the other PHP in this case)… so that you don’t have to rewrite parts of your (someonelse’s) .NET application for another PHP application running on a linux box for example.

    This has nothing to do with PDO by the way.

  3. dsoehner says:

    The instructions say to modify the php.ini file and execute come code on the command line.  Since my site is hosted at Network Solutions, I don’t have write access to the php.ini file nor can I execute code on the command line.

    Is there a workaround? 

  4. To dsoehner

    Changes to the PHP.INI file are necessary only if the XML/XSL and CURL extensions are not already enabled. You can check which extensions are enable by calling the phpinfo function.

    You don’t need to run the command line tool on the same machine where you application is running. The command line tool is used only to generate a PHP file that needs to included in your PHP application. You can run the command line tool on your desktop (assuming you can access the ADO.NET Data Service that you want to use) and then copy the file it generates on the server where your PHP application is hosted.


  5. emmanuelyazid says:

    To dsoehner

    "The instructions say to modify the php.ini file and execute come code on the command line.  Since my site is hosted at Network Solutions, I don’t have write access to the php.ini file nor can I execute code on the command line.

    Is there a workaround?"

    Read this before



    Check your php config information. <?php phpinfo(); ?>

    Alternatively you can load the module dynamically in your php code using syntax :




    for Linux


  6. dsoehner says:

    claudioc – I ran the PHPDataSvcUtil from my local machine and it was a complete success.  The remaining steps of the tutorial went smoothly and I’m now able to extract the data I need with this great utility.  Thank you!

  7. bhavtosh says:

    pretty nice and good move from microsoft to enable developers to keep UI on php and DAL on .net

    this is a good way to start from and new ways to allow two technologies to talk and work

  8. Tim Brookins says:

    I downloaded the code and it does not work. What a piece of crap this is.

  9. JC Cimetiere says:

    @Tim Brookins: maybe you could explain a little bit what’s  not working. They we could try to help 🙂

    my 2 cents.


  10. Sorr Bei says:

    I’m interested on this, but I’m having problem with creating the ADO.NET Data Services. I had installed the .Net Framework 3.5 Sp1 but the ADO.Net Data Entity Model doesn’t show up.

    What do you think I’m missing?


  11. To Sorr Bei

    Did you install VS 2008 SP1 too?

    SV 2008 SP1 includes all the VS components needed to build an ADO.NET Data Service including the Data Entity model