Welcome to MSDN Blogs Sign in | Join | Help

Interoperability @ Microsoft

Covering interoperability scenarios, the technologies enabling them and the community at large

News

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

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.

Posted: Friday, August 21, 2009 1:00 AM by claudioc

Comments

Phillip Jain said:

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

# August 22, 2009 2:48 AM

yop said:

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.

# August 24, 2009 3:26 PM

dsoehner said:

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? 

# August 24, 2009 4:32 PM

claudioc said:

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.

Claudio

# August 24, 2009 5:56 PM

emmanuelyazid said:

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

http://www.php.net/manual/en/ini.core.php#id3861895

http://www.php.net/manual/en/configuration.changes.php

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

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

<?php

dl("php_curl.dll");

?>

for Linux

dl("php_curl.so");

# August 24, 2009 7:20 PM

dsoehner said:

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!

# August 25, 2009 11:20 AM

bhavtosh said:

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

# September 7, 2009 8:21 AM

Tim Brookins said:

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

# September 9, 2009 6:53 AM

jccim said:

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

my 2 cents.

JC

# September 9, 2009 11:48 PM

Sorr Bei said:

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?

Thanks...

# November 30, 2009 6:06 PM

claudioc said:

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

Claudio

# December 1, 2009 10:17 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker