<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dimuthu's Blog &#187; DataService</title>
	<atom:link href="http://www.dimuthu.org/tag/dataservice/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dimuthu.org</link>
	<description>Waiting for your comments</description>
	<lastBuildDate>Wed, 21 Dec 2011 05:39:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<image>
  <link>http://www.dimuthu.org</link>
  <url>http://www.dimuthu.org/favicon.ico</url>
  <title>Dimuthu's Blog</title>
</image>
		<item>
		<title>PHP Data Services with PostgreSQL</title>
		<link>http://www.dimuthu.org/blog/2008/12/07/php-data-services-with-postgresql/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/07/php-data-services-with-postgresql/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 12:56:19 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[DataServices]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[pdo_pgsql]]></category>
		<category><![CDATA[pgsql]]></category>
		<category><![CDATA[postgresql]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=771</guid>
		<description><![CDATA[LAMP (Linux + Apache + Mysql + PHP) stack powers many servers in the Internet today. For a LAMP  server, PostgreSQL could be the first alternative to Mysql. Similar to PHP + MySQL,  PHP + PostgreSQL too can be easily used in to host data services. Here are the steps to do it. If you [...]]]></description>
			<content:encoded><![CDATA[<p>LAMP (Linux + Apache + Mysql + PHP) stack powers many servers in the Internet today. For a LAMP  server, PostgreSQL could be the first alternative to Mysql. Similar to PHP + MySQL,  PHP + PostgreSQL too can be easily used in to host data services. Here are the steps to do it.</p>
<ol>
<li> If you already don&#8217;t have Apache + PHP + PostgreSQL download them from the following locations. Apache &#8211; <a href="http://httpd.apache.org/download.cgi">http://httpd.apache.org/download.cgi</a>, PHP &#8211; <a href="http://php.net">http://php.net</a> and PostgreSQL &#8211; <a href="http://www.postgresql.org/download/">http://www.postgresql.org/download/</a></li>
<li> You have to enable the PHP pdo_pgsql, pdo and pgsql plugins. Read <a href="http://www.php.net/manual/en/pgsql.setup.php">here </a>for the instructions to setup these libraries. (For an example: if you are windows you have to set the system &#8216;PATH&#8217; variable to the &lt;postgresql_installed_dir&gt;/bin directory.</li>
<li> If you already don&#8217;t have <a href="http://wso2.org/projects/wsf/php">WSF/PHP,</a> download and install it according to the guidelines provided in <a href="http://wso2.org/project/wsf/php/2.0.0/docs/install_guide.html">wsf/php installation guide</a>.<em>NOTE: You can check pdo_pgsql and wsf/php has properly installed with the help of phpinfo() function.</em></li>
<li> Now lets start with creating a sample Database table. For this example I created a database called &#8216;workshop&#8217;, schema called &#8216;workshop&#8217; and inside there the table &#8216;Employee&#8217; with the following schema.<br />
<table border="1">
<tbody>
<tr style="background: #dddddd">
<td>Column Name</td>
<td>Column Type</td>
</tr>
<tr>
<td>employId</td>
<td>integer</td>
</tr>
<tr>
<td>name</td>
<td>character varying</td>
</tr>
<tr>
<td>email</td>
<td>character varying</td>
</tr>
<tr>
<td>jobTitle</td>
<td>character varying</td>
</tr>
<tr>
<td>project</td>
<td>character varying</td>
</tr>
</tbody>
</table>
<p><em>Note: You can use <a href="http://phppgadmin.sourceforge.net/">phpPgAdmin</a> (web based) or <a href="http://www.pgadmin.org/">pgAdmin III </a>to create tables from GUI </em></li>
<li> Then you can write a small php script to expose the data in the above table as a web service.
<pre class="php"><span style="font-weight: bold; color: #000000;">&lt;?php</span>

<span style="font-style: italic; color: #808080;">//Including the Data Services library</span>
<span style="color: #b1b100;">require_once</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"wso2/DataServices/DataService.php"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// Including the connection information (i.e. PGSQUL USERNAME</span>
<span style="font-style: italic; color: #808080;">// and PGSQL_PASSWORD) for my PGSQL Connection</span>
<span style="color: #b1b100;">require_once</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"constants.php"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// database configurations</span>
<span style="color: #0000ff;">$config</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
		<span style="color: #ff0000;">"db"</span> =&gt; <span style="color: #ff0000;">"pgsql"</span>,
		<span style="color: #ff0000;">"username"</span> =&gt; PGSQL_USERNAME,
		<span style="color: #ff0000;">"password"</span> =&gt; PGSQL_PASSWORD,
		<span style="color: #ff0000;">"dbname"</span> =&gt; <span style="color: #ff0000;">"workshop"</span>,
		<span style="color: #ff0000;">"dbhost"</span> =&gt; <span style="color: #ff0000;">"localhost"</span>
		<span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$output_format</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
                    <span style="color: #ff0000;">"resultElement"</span> =&gt; <span style="color: #ff0000;">"employees"</span>,
                    <span style="color: #ff0000;">"rowElement"</span> =&gt; <span style="color: #ff0000;">"employee"</span>,
                    <span style="color: #ff0000;">"elements"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
			    <span style="color: #ff0000;">"id"</span> =&gt; <span style="color: #ff0000;">"employeeId"</span>,
                            <span style="color: #ff0000;">"name"</span> =&gt; <span style="color: #ff0000;">"name"</span>,
                            <span style="color: #ff0000;">"email"</span> =&gt; <span style="color: #ff0000;">"email"</span>,
                            <span style="color: #ff0000;">"jobTitle"</span> =&gt; <span style="color: #ff0000;">"jobTitle"</span>,
                            <span style="color: #ff0000;">"project"</span> =&gt; <span style="color: #ff0000;">"project"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$sql</span> = <span style="color: #ff0000;">"SELECT * FROM workshop.Employees"</span>;

<span style="color: #0000ff;">$get_employees_op</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"outputFormat"</span> =&gt; <span style="color: #0000ff;">$output_format</span>, <span style="color: #ff0000;">"sql"</span> =&gt; <span style="color: #0000ff;">$sql</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$get_employees_url</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"HTTPMethod"</span> =&gt; <span style="color: #ff0000;">"GET"</span>, <span style="color: #ff0000;">"RESTLocation"</span> =&gt; <span style="color: #ff0000;">"employees"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// list of operations</span>
<span style="color: #0000ff;">$operations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
                <span style="color: #ff0000;">"getEmployees"</span> =&gt; <span style="color: #0000ff;">$get_employees_op</span>,
                <span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// list of rest url mappping (operation =&gt; url)</span>
<span style="color: #0000ff;">$restmap</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
                <span style="color: #ff0000;">"getEmployees"</span> =&gt; <span style="color: #0000ff;">$get_employees_url</span>,
                <span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// creating DSService and reply</span>
<span style="color: #0000ff;">$service</span> = <span style="font-weight: bold; color: #000000;">new</span> DataService<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
         <span style="color: #ff0000;">"config"</span> =&gt; <span style="color: #0000ff;">$config</span>,
         <span style="color: #ff0000;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</span>, <span style="color: #ff0000;">"RESTMapping"</span>=&gt;<span style="color: #0000ff;">$restmap</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$service</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</pre>
<pre class="php"><span style="font-weight: bold; color: #000000;">?&gt;</span></pre>
</li>
<li> We just wrote a PostgreSQL Data Services that provides its service as both REST and SOAP form. To deploy this service, We just need to copy this in to the web root directory. And the web URL for the script will be the endpoint to the web service.</li>
<li>We can test the service either by calling its SOAP interface, which we may need to write a small SOAP client or by calling its REST interface, which only need a GET request from the browser. Say my script name is &#8220;my_dataservice.php&#8221; and I&#8217;ve put it in the web root directory, then the URL to call the REST interface of the service is
<pre>http://localhost/my_dataservice.php/employees</pre>
</li>
</ol>
<p><strong>WSDL Generation for PostgreSQL Data Service</strong><br />
You can get the WSDL for the service from the URL formed adding the suffix &#8220;?wsdl&#8221; (or &#8220;?wsdl2&#8243; to wsdl v2.0)  to the service URL,</p>
<pre>http://localhost/my_dataservice.php?wsdl</pre>
<p>Here all the schema data types are shown as xsd:anyType, which may not be the behavior that you want. In fact you can provide the schema data types to the fields from the code itself. Lets change the $outputFormat variable to provide the schema information as well using the following code snip.</p>
<pre class="php"><span style="color: #0000ff;">$output_format</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
                    <span style="color: #ff0000;">"resultElement"</span> =&gt; <span style="color: #ff0000;">"employees"</span>,
                    <span style="color: #ff0000;">"rowElement"</span> =&gt; <span style="color: #ff0000;">"employee"</span>,
                    <span style="color: #ff0000;">"elements"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
			    <span style="color: #ff0000;">"id"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"column"</span> =&gt; <span style="color: #ff0000;">"employeeId"</span>,
		    			  <span style="color: #ff0000;">"xsdType"</span> =&gt; <span style="color: #ff0000;">"xsd:int"</span><span style="color: #66cc66;">)</span>,
			    <span style="color: #ff0000;">"name"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"column"</span> =&gt; <span style="color: #ff0000;">"name"</span>,
		    			  <span style="color: #ff0000;">"xsdType"</span> =&gt; <span style="color: #ff0000;">"xsd:string"</span><span style="color: #66cc66;">)</span>,
			    <span style="color: #ff0000;">"email"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"column"</span> =&gt; <span style="color: #ff0000;">"email"</span>,
		    			  <span style="color: #ff0000;">"xsdType"</span> =&gt; <span style="color: #ff0000;">"xsd:string"</span><span style="color: #66cc66;">)</span>,
			    <span style="color: #ff0000;">"jobTitle"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"column"</span> =&gt; <span style="color: #ff0000;">"jobTitle"</span>,
		    			  <span style="color: #ff0000;">"xsdType"</span> =&gt; <span style="color: #ff0000;">"xsd:string"</span><span style="color: #66cc66;">)</span>,
			    <span style="color: #ff0000;">"project"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"column"</span> =&gt; <span style="color: #ff0000;">"project"</span>,
		    			  <span style="color: #ff0000;">"xsdType"</span> =&gt; <span style="color: #ff0000;">"xsd:string"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>Note that you provide the xsd type for each field explicitly. In fact this change is not needed for mysql pdo extension since it allows identifying field types programatically. Since this feature is not available in all the other pdo drivers, we have to explicitly give xsd type information for them.</p>
<p>If you wan to provide data services with SQLite or MSSQL, You can check my other posts on <a href="http://www.dimuthu.org/blog/2008/10/04/mssqlmicrosoft-sql-data-services-in-php/">MSSQL(Microsoft SQL) Data Services In PHP</a> and <a href="http://www.dimuthu.org/blog/2008/10/05/data-services-with-sqlite-in-php/">Data Services with SQLite in PHP</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/07/php-data-services-with-postgresql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>RESTful URL Mapping in WSF/PHP</title>
		<link>http://www.dimuthu.org/blog/2008/11/16/restful-url-mapping-in-wsfphp/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/16/restful-url-mapping-in-wsfphp/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 17:21:49 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[RESTfulSchool]]></category>
		<category><![CDATA[URL Mapping]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=621</guid>
		<description><![CDATA[In a RESTful design, choose of URLs for resources are really important. The URL uniquely represents a resource. Service consumers can change some parts in the URL to access different other resources. So it is clear that the URL consists of some constant parts which describe the resource group or catalog in general and some [...]]]></description>
			<content:encoded><![CDATA[<p>In a RESTful design, choose of URLs for resources are really important. The URL uniquely represents a resource. Service consumers can change some parts in the URL to access different other resources. So it is clear that the URL consists of some constant parts which describe the resource group or catalog in general and some variable parts which have different and unique values for different resources.</p>
<p>As an example look at the following URL patterns</p>
<ul>
<li>students/{name} &#8211; The constant &#8216;students&#8217; represent the students group in general and the variable &#8216;name&#8217; is used to identify each student individually.</li>
<li>students/{name}/marks/{subject} &#8211; The constants &#8216;students&#8217; and &#8216;marks&#8217; shows that this resource is a marks of some students, The two variables &#8216;name&#8217; and &#8216;subjects&#8217; addresses which student and marks of which subject is presented in the URL.</li>
</ul>
<p>You can have a look at some of the uses of such mappings from <a href="http://labs.wso2.org/wsf/php/resource_view.php?url=RESTfulSchool">RESTful School demo</a>.</p>
<p><a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> allows you to create RESTful Web Services and further more RESTful Data Services in PHP.</p>
<p>In a RESTful Data Service you expose a database query as a web service. There you can write a prepared statement and feed arguments for the statement through the variable parameters of the URL. For an example take the <a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2FRESTFulSchool%2Fschool_service.php">RESTfulSchool Demo Code</a>.</p>
<p>To retrieve a particular student, we can use the following prepared statement and the URL pattern ( This URL Pattern+  HTTP &#8216;GET&#8217; method is matched to execute this query. )</p>
<pre class="php"><span style="color: #0000ff;">$sql</span> = <span style="color: #ff0000;">"SELECT * FROM Students where StudentName = ?"</span>

<span style="color: #0000ff;">$get_students_with_name_url</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"HTTPMethod"</span> =&gt; <span style="color: #ff0000;">"GET"</span>,
                 <span style="color: #ff0000;">"RESTLocation"</span> =&gt; <span style="color: #ff0000;">"students/{name}"</span><span style="color: #66cc66;">)</span>;</pre>
<p>So you can execute this prepared statement with the subject name &#8216;John&#8217; using the following URL.</p>
<pre><a href="http://labs.wso2.org/wsf/php/solutions/RESTFulSchool/school_service.php/students/john">http://labs.wso2.org/wsf/php/solutions/RESTFulSchool/school_service.php/students/john</a></pre>
<p>If your service is not exposing the database directly, then you have to choose the general web service API rather than the data service specific API. In there you will be able to write your business logic for publishing student information in a PHP function and expose it as a web service.</p>
<p>In such a cas,e your function is taking an argument which of type <a href="http://wso2.org/project/wsf/php/2.0.0/docs/api_content.html#message">WSMessage</a>. This structure hold an XML that contains values for all the variable parameters as in the users request URL. For an example for above REST Mapping, we can expect the following XML.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;getSubject<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;name<span style="font-weight: bold; color: black;">&gt;</span></span></span>Chemistry<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/getSubject<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>And your function to expose as a service, would be look like this,</p>
<pre class="php"><span style="font-weight: bold; color: #000000;">function</span> getSubject<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #808080;">/* retrieve the subject name from the
       $input xml using simple xml */</span>

    <span style="color: #0000ff;">$input_xml</span> = <span style="font-weight: bold; color: #000000;">new</span> SimpleXMLElement<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">str</span><span style="color: #66cc66;">)</span>;

    <span style="color: #0000ff;">$subject_name</span> = <span style="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">name</span>;

    <span style="font-style: italic; color: #808080;">/* write the logic to retrieve subject information
      for the $subject_name */</span>

    ....
<span style="color: #66cc66;">}</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/16/restful-url-mapping-in-wsfphp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Data Services with SQLite in PHP</title>
		<link>http://www.dimuthu.org/blog/2008/10/05/data-services-with-sqlite-in-php/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/05/data-services-with-sqlite-in-php/#comments</comments>
		<pubDate>Sun, 05 Oct 2008 10:21:22 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[SQLite]]></category>
		<category><![CDATA[wsf/php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=440</guid>
		<description><![CDATA[Yesterday I wrote a how-to on doing MSSQL DataService in PHP. It was just about installing necessary PDO drivers and setting the following configurations about your Database. // database configurations $config = array( "db" =&#62; "mssql", "username" =&#62; DB_USERNAME "password" =&#62; DB_PASSWORD "dbname" =&#62; DB_NAME, "dbhost" =&#62; DB_SERVER_NAME ); But when it comes to SQLite [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I wrote a how-to on doing <a href="http://www.dimuthu.org/blog/2008/10/04/mssqlmicrosoft-sql-data-services-in-php/">MSSQL DataService in PHP</a>. It was just about installing necessary PDO drivers and setting the following configurations about your Database.</p>
<pre class="php"><span style="font-style: italic; color: #808080;">// database configurations</span>
<span style="color: #0000ff;">$config</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
		<span style="color: #ff0000;">"db"</span> =&gt; <span style="color: #ff0000;">"mssql"</span>,
		<span style="color: #ff0000;">"username"</span> =&gt; DB_USERNAME
		<span style="color: #ff0000;">"password"</span> =&gt; DB_PASSWORD
		<span style="color: #ff0000;">"dbname"</span> =&gt; DB_NAME,
		<span style="color: #ff0000;">"dbhost"</span> =&gt; DB_SERVER_NAME
		<span style="color: #66cc66;">)</span>;</pre>
<p>But when it comes to SQLite you don&#8217;t have such thing called database server, name, username or password. It is just a file in your computer. In this kind of situation you can directly use the PDO DSN (standards for Data Source Name) string to configure your database.</p>
<pre class="php"><span style="font-style: italic; color: #808080;">// giving my sqlite database file information</span>
<span style="color: #0000ff;">$config</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
    <span style="color: #ff0000;">"dsn"</span> =&gt; <span style="color: #ff0000;">"sqlite2:mydbfile.db"</span><span style="color: #66cc66;">)</span>;</pre>
<p>So this is all specific to SQLite. For the rest of the code, you don&#8217;t need to worry about the underlying database you use. Please read the blog about the <a href="http://www.dimuthu.org/blog/2008/09/06/php-dataservices-2-minutes-introduction/">PHP DataServices 2 Minutes Introduction</a> for short guide on PHP data services in general.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/05/data-services-with-sqlite-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Online Tools for PHP Web Services Developers</title>
		<link>http://www.dimuthu.org/blog/2008/09/28/online-tools-for-php-web-services-developers/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/28/online-tools-for-php-web-services-developers/#comments</comments>
		<pubDate>Sun, 28 Sep 2008 10:19:02 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[.dbs]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[dbs2php]]></category>
		<category><![CDATA[demo site]]></category>
		<category><![CDATA[online]]></category>
		<category><![CDATA[php2wsdl]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[wsdl2php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=401</guid>
		<description><![CDATA[PHP Web Services Demo Site contains a set of nice tools that help development of web services in PHP. WSDL2PHP tool &#8211; This allow you to generate PHP code for your WSDL. Note that this need your wsdl to be in a URL that it can access. PHP2WSDL tool &#8211; Here you can paste your [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://labs.wso2.org/wsf/php">PHP Web Services Demo Site</a> contains a set of nice tools that help development of web services in PHP.</p>
<ul>
<li><a href="http://labs.wso2.org/wsf/php/wsdl2phptool.php">WSDL2PHP tool</a> &#8211; This allow you to generate PHP code for your WSDL. Note that this need your wsdl to be in a URL that it can access.</li>
<li><a href="http://labs.wso2.org/wsf/php/php2wsdltool.php">PHP2WSDL tool</a> &#8211; Here you can paste your annotated PHP code and get the WSDL (both version 1.1 and 2.0) generated.  You can find the annotation syntax <a href="http://wso2.org/project/wsf/php/2.0.0/docs/wsdl_generation_api.html">in here</a>.</li>
<li><a href="http://labs.wso2.org/wsf/php/dbs2phptool.php">DBS2PHP tool</a> &#8211; WSO2 has Data Services library implemented in both Java and PHP. In <a href="http://wso2.org/projects/solutions/data-services/java">Java Data Services</a> you give the <a href="http://wso2.org/wiki/display/wsf/Data+Services+and+Resources">configuration via an XML</a> (in .dbs extension). Whereas in PHP you give the configuration via <a href="https://wso2.org/wiki/display/wsfphp/API+for+Data+Services+Revised">a simple PHP code which use arrays</a> to feed the configuration parameters. If you are more familiar in writing XML than PHP, you can first write the XML and then convert it to PHP using DBS2PHP tool.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/28/online-tools-for-php-web-services-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RESTful CRUD Data Services Demo</title>
		<link>http://www.dimuthu.org/blog/2008/09/27/restful-crud-data-services-demo/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/27/restful-crud-data-services-demo/#comments</comments>
		<pubDate>Sat, 27 Sep 2008 09:35:00 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[applications]]></category>
		<category><![CDATA[CRUD]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=391</guid>
		<description><![CDATA[When you are developing Web Service for CRUD (Create, Read, Update, Delete) operations you may find it is easy to implement it as RESTful service. In this Demo on RESTful CRUD Service You can have an idea how you develop such a service with WSO2 WSF/PHP. Here we take a scenario of submitting applications (say [...]]]></description>
			<content:encoded><![CDATA[<p>When you are developing Web Service for CRUD (<strong>C</strong>reate, <strong>R</strong>ead,  <strong>U</strong>pdate, <strong>D</strong>elete) operations you may find it is easy to implement it as RESTful service. In this <a href="http://labs.wso2.org/wsf/php/resource_view.php?url=RESTFulCRUD">Demo on RESTful CRUD Service</a> You can have an idea how you develop such a service with <a href="http://wso2.org/projects/wsf/php">WSO2 WSF/PHP</a>.</p>
<p>Here we take a scenario of submitting applications (say for a school).</p>
<p>In RESTful world we map a resource to a unique URL. In this demo, application is a resource. We use the URL &#8220;application/{id}&#8221; to represent a particular application with the id {id}.</p>
<p>You can  use  HTTP verb + Resource URL touples to manipulate the resource with CRUD operations.  Here is how it is done in this particular demonstration.</p>
<table border="1">
<tbody>
<tr style="background-color:#CCCCCC;">
<td>Request format (HTTP Verb + URL)</td>
<td>Operation Semantic</td>
</tr>
<tr>
<td>POST applications/{id}</td>
<td>Create an application</td>
</tr>
<tr>
<td>GET applications/{id}</td>
<td>Get an application</td>
</tr>
<tr>
<td>PUT applications/{id}</td>
<td>Change an application</td>
</tr>
<tr>
<td>DELETE applications/{id}</td>
<td>Delete an application</td>
</tr>
</tbody>
</table>
<p>Go for the <a href="http://labs.wso2.org/wsf/php/demo.php?name=RESTFulCRUD&amp;demo=CRUDApplications/demo_client.php&amp;src=./CRUDApplications">wsf/php demo site</a>for the live demo of this service. Visit the <a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2F.%2FCRUDApplications%2Fschool_applications.php">demo service source code</a> to see how easy to implement it with WSF/PHP Data Services library.</p>
<p>I wrote a similar <a href="http://www.dimuthu.org/blog/2008/09/18/do-rest-in-php-php-restful-data-services/">blog on Data Services</a> last week to demonstrate how you design the mapping of url to different resources in a RESTful Service.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/27/restful-crud-data-services-demo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Do REST in PHP &#8211; PHP RESTful Data Services</title>
		<link>http://www.dimuthu.org/blog/2008/09/18/do-rest-in-php-php-restful-data-services/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/18/do-rest-in-php-php-restful-data-services/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 18:04:49 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[DELETE]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[PUT]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[ROA]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[WOA]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=293</guid>
		<description><![CDATA[In RESTful paradigm we give a piece of data ( or in other word &#8216;Resource&#8217;) a unique URL. And in order to manipulate data we use HTTP verbs POST/PUT (create, update), GET (read), DELETE (delete). For an example take the scenario of manipulating Students data in a high school. Here is how each operation is [...]]]></description>
			<content:encoded><![CDATA[<p>In RESTful paradigm we give a piece of data ( or in other word &#8216;Resource&#8217;) a unique URL. And in order to manipulate data we use HTTP verbs POST/PUT (create, update), GET (read), DELETE (delete). For an example<br />
take the scenario of manipulating Students data in a high school. Here is how each operation is mapped to a http request (URL + HTTP verb)</p>
<table border="1">
<tbody>
<tr style="background-color:#cccccc">
<td>HTTP request</td>
<td>Operation</td>
</tr>
<tr>
<td>POST api/students/ben</td>
<td>Create the resource (peice of data) called ben as a student. HTTP body or the url itself (e.g. api/students/ben?age=15&amp;country=xx) may contain the required information about ben</td>
</tr>
<tr>
<td>GET api/students/ben</td>
<td>Retrieve the information about ben.</td>
</tr>
<tr>
<td>PUT api/students/ben</td>
<td>Update ben</td>
</tr>
<tr>
<td>DELETE api/student/ben</td>
<td>Delete the student called &#8216;ben&#8217;.</td>
</tr>
</tbody>
</table>
<p>With the addition of all these HTTP verbs <a href="http://wso2.org/projects/wsf/php">WSO2 WSF/PHP 2.0.0</a> become a great tool for RESTful developers. Specially with the introducing Data Services library it was so easy to make your database a REST service. I m thinking of preparing a series of application to demonstrate the power of WSF/PHP with all these new features.</p>
<p>This demo -<a href="http://labs.wso2.org/wsf/php/demo.php?name=RESTfulSchool&amp;demo=RESTFulSchool/demo_client.php&amp;src=RESTFulSchool">RESTful School</a>- shows  how you map a URL to a peice of data. Here we use only the http &#8220;GET&#8221; method (which is the most to used in practicle data service).</p>
<p>Here is some description of the operations you find in there. Just check <a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2FRESTFulSchool%2Fschool_service.php"> the source code for RESTful School demo</a> to see how this is done in code level.</p>
<table border="1">
<tbody>
<tr style="background-color:#cccccc">
<td>Operation</td>
<td>URL</td>
<td>SQL Query</td>
<td>Note</td>
</tr>
<tr>
<td>Get All subjects</td>
<td>
<pre><span style="color: #ff0000;">subjects</span></pre>
</td>
<td>
<pre><span style="color: #ff0000;">SELECT subjectName, subjectTeacher FROM Subjects</span></pre>
</td>
<td>With no parameters</td>
</tr>
<tr>
<td>Get subject information From Name</td>
<td>
<pre><span style="color: #ff0000;">subjects/{name}</span></pre>
</td>
<td>
<pre><span style="color: #ff0000;">SELECT subjectName, subjectTeacher FROM Subjects where SubjectName = ?</span></pre>
</td>
<td>The single parameter feed from prepared statement syntax</td>
</tr>
<tr>
<td>Get All students</td>
<td>
<pre><span style="color: #ff0000;">students</span></pre>
</td>
<td>
<pre><span style="color: #ff0000;">SELECT * FROM Students</span></pre>
</td>
<td>Again no parameters</td>
</tr>
<tr>
<td>Get students From Name</td>
<td>
<pre><span style="color: #ff0000;">students/{name}</span></pre>
</td>
<td>Inner Query:</p>
<pre><span style="color: #ff0000;">SELECT subjectName, marks FROM Marks m, Subjects s "</span>.
        <span style="color: #ff0000;">" where m.studentId = ? and m.subjectID = s.subjectId
</span></pre>
<p>Outer Query</p>
<pre><span style="color: #ff0000;">SELECT * FROM Students where StudentName = ?</span></pre>
</td>
<td>Nested query, Inner query is called from outer query</td>
</tr>
<tr>
<td>Get Marks per Students per Subjects</td>
<td>
<pre><span style="color: #ff0000;">students/{student}/</span><span><span style="color: #ff0000;">marks/</span></span><span style="color: #ff0000;">{subject}</span></pre>
</td>
<td>
<pre><span style="color: #ff0000;">SELECT marks FROM Marks, Subjects, Students where StudentName = ?"</span>.
        <span style="color: #ff0000;">" and SubjectName = ? and Marks.subjectId = Subjects.subjectId"</span>.
        <span style="color: #ff0000;">" and Marks.studentID = Students.StudentId;</span></pre>
</td>
<td>Two parameters, and &#8216;?&#8217; in the sql query..</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/18/do-rest-in-php-php-restful-data-services/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PHP Data Services With WS-Security</title>
		<link>http://www.dimuthu.org/blog/2008/09/16/php-data-services-with-ws-security/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/16/php-data-services-with-ws-security/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 16:22:02 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[Authentication. Username Token]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[policy]]></category>
		<category><![CDATA[securityToken]]></category>
		<category><![CDATA[ws-security]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=277</guid>
		<description><![CDATA[Earlier I wrote a blog about how to make your wordpress blog a web service using the WSF/PHP Data Services library. I will expand that post to demonstrate the use of WS-Security features with WSF/PHP. This time it is a Tag Search service for my wordpress blog. Check the &#8216;Tag Search&#8217; Data Services Demo from [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier I wrote a blog about <a href="http://www.dimuthu.org/blog/2008/08/11/make-your-wordpress-blog-a-web-service-in-few-step/">how to make your wordpress blog a web service</a> using the <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> Data Services library. I will expand that post to demonstrate the use of WS-Security features with WSF/PHP.</p>
<p>This time it is a Tag Search service for my wordpress blog. Check the &#8216;Tag Search&#8217; Data Services Demo from <a href="http://ws.dimuthu.org/">http://ws.dimuthu.org/</a>. The only difference is here you are authenticated before accessing the service using the username tokens as specified in WS-Security.</p>
<p>Just look at the WSSecurity constructor in the <a href="http://ws.dimuthu.org/source.php?src=tag.search.service">Data Service Demo Code</a>. You can observe 4 new parameters passed in to it. (In addition to the &#8220;config&#8221; and &#8220;operations&#8221; options)</p>
<ul>
<li>policy &#8211; This is where you specify the policy governed by the service.  Here you can either use the WS-Policy compliant policy file or just a simple PHP array that contain the required security token informations.
<pre><span style="color: #0000ff;">$sec_array</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"useUsernameToken"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$policy</span> = <span style="font-weight: bold; color: #000000;">new</span> WSPolicy<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"security"</span>=&gt;<span style="color: #0000ff;">$sec_array</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
</li>
<li> securityToken: You specify the user parameters like how you handle the authentication and the encoding type in this option.
<pre><span style="color: #0000ff;">$security_token</span> = <span style="font-weight: bold; color: #000000;">new</span> WSSecurityToken<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"passwordCallback"</span> =&gt; <span style="color: #ff0000;">"password_callback_function"</span>,
                                       <span style="color: #ff0000;">"passwordType"</span> =&gt; <span style="color: #ff0000;">"Digest"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">/* callback function
 * @param string $username username of the client request
 * @return string $password password for that username
 */</span>
<span style="font-weight: bold; color: #000000;">function</span> password_callback_function<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$username</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #808080;">// In the real word I should authenticate users from database.</span>
    <span style="font-style: italic; color: #808080;">// for this demo I have a simple if-else block</span>

    <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$username</span> == <span style="color: #ff0000;">"visitor"</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
        <span style="color: #b1b100;">return</span> <span style="color: #ff0000;">"visitor123"</span>;
    <span style="color: #66cc66;">}</span>

    <span style="color: #b1b100;">return</span> <span style="color: #ff0000;">"notavistor"</span>;
<span style="color: #66cc66;">}</span></pre>
<p>Note that here you specify a callback function to the security token parameter. Inside this function you retrieve the password for the user (mostly from the database) and return. WSF/PHP will authenticate the user from these information.</li>
<li> useWSA : You need to set this option in order to generate the WS-Addressing parameters (like action) for your WSDL. WS-Addressing is required to run web services with WS-Security in WSF/PHP.</li>
<li> actions: You should provide a map of action to service operations in order to get the WS Addressing information generated with your WSDL.
<pre><span style="color: #0000ff;">$actions</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"http://ws.dimuthu.org/blog/getPosts"</span> =&gt; <span style="color: #ff0000;">"getPosts"</span><span style="color: #66cc66;">)</span>;</pre>
<p>Just have a look at how these information are rendered in the generated WSDL, <a href="http://ws.dimuthu.org/blog/WordpressTagSearchService.php?wsdl">http://ws.dimuthu.org/blog/WordpressTagSearchService.php?wsdl</a>. (Note the wsaw:action attribute in the messages inside the portType element.</li>
</ul>
<p>After you deploy the service, it is very easy to generate a client with the WSDL. If you write clients in PHP you can use the wsdl2php tool shipping with WSF/PHP.  The code for my demo client can be found in <a href="http://ws.dimuthu.org/source.php?src=tag.search.client">http://ws.dimuthu.org/source.php?src=tag.search.client</a>. (There I have hard coded the username and password just for the demo purpose)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/16/php-data-services-with-ws-security/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>WSO2 WSF/PHP 2.0.0 Just Released!</title>
		<link>http://www.dimuthu.org/blog/2008/09/12/wso2-wsfphp-200-just-released/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/12/wso2-wsfphp-200-just-released/#comments</comments>
		<pubDate>Fri, 12 Sep 2008 10:29:52 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[2.0.0]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[features]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[WS-*]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=253</guid>
		<description><![CDATA[We have been waiting for a while to do the WSF/PHP 2.0.0 release with a bundle of new features. We took time to test all the features and to make sure they are working smoothly. And it is heavily tested for the interoperability specially with .NET for WS-Security and WS-Reliable Messaging scenarios. And the newly [...]]]></description>
			<content:encoded><![CDATA[<p>We have been waiting for a while to do the <a href="http://wso2.org/projects/wsf/php">WSF/PHP 2.0.0</a> release with a bundle of new features. We took time to test all the features and to make sure they are working smoothly. And it is heavily tested for the interoperability specially with .NET for WS-Security and WS-Reliable Messaging scenarios. And the newly added Data Services library will be a great tool for the PHP community to bring their LAMP/WAMP applications to the SOA platform. WSF/PHP 2.0.0 is not just a SOAP library. It is ready for the RESTful applications as well with the improved support for HTTP verbs.</p>
<p>Here is the list of new features introduced in this release</p>
<ul>
<li>Added PKCS12 Keystore Support</li>
<li>Added Secure Conversation Support</li>
<li>Added Replay Detection Support</li>
<li>Contract First Web Services support for MTOM</li>
<li>SWA ( Soap With Attachments ) Support added</li>
<li>MTOM Attachment caching support added</li>
<li>HTTP Chunking support added</li>
<li>REST API Improved to support HTTP verbs GET,DELETE,PUT and POST</li>
<li>New PHP Data Services Solution</li>
<li>WS-RM 1.1 added</li>
</ul>
<p>Have look at the <a href="http://wso2.org/project/wsf/php/2.0.0/release-note.html">WSF/PHP 2.0.0 Official Release Note</a> for the complete feature list</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/12/wso2-wsfphp-200-just-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP DataServices 2 Minutes Introduction</title>
		<link>http://www.dimuthu.org/blog/2008/09/06/php-dataservices-2-minutes-introduction/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/06/php-dataservices-2-minutes-introduction/#comments</comments>
		<pubDate>Sat, 06 Sep 2008 16:52:12 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[DataServices]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=225</guid>
		<description><![CDATA[We use the term DataServices for exposing a Database as a WebService. PHP DataServices library make this task easy by providing a very simple API to the developers. The API is designed to let the service developer to provide the database configurations, input message format, output message format and the SQL query information. So reading [...]]]></description>
			<content:encoded><![CDATA[<p>We use the term DataServices for exposing a Database as a WebService. PHP DataServices library make this task easy by providing a very simple API to the developers.</p>
<p>The API is designed to let the service developer to provide the database configurations, input message format, output message format and the SQL query information. So reading and parsing the input SOAP message, building the response SOAP message from the queried data, serving the WSDL and providing the Database independent layer (with the help of PDO extensions) are done by the Dataserivce library.</p>
<p><strong>Configurations</strong></p>
<p>You give your database configurations in this format.</p>
<pre><span style="font-style: italic; color: #808080;">// database configuraitons</span>
<span style="color: #0000ff;">$config</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
      <span style="color: #ff0000;">"db"</span> =&gt; <span style="color: #ff0000;">"mysql"</span>, <span style="font-style: italic; color: #808080;">//your sql</span>
      <span style="color: #ff0000;">"username"</span> =&gt; DB_USERNAME, <span style="font-style: italic; color: #808080;">//your username</span>
      <span style="color: #ff0000;">"password"</span> =&gt; DB_PASSWORD, <span style="font-style: italic; color: #808080;">//your password</span>
      <span style="color: #ff0000;">"dbname"</span> =&gt; <span style="color: #ff0000;">"ds"</span>, <span style="font-style: italic; color: #808080;">//your database name</span>
      <span style="color: #ff0000;">"dbhost"</span> =&gt; <span style="color: #ff0000;">"localhost"</span><span style="color: #66cc66;">)</span>; <span style="font-style: italic; color: #808080;">//your database host</span></pre>
<p><strong>Input Format</strong></p>
<p>You have to declare the names and the types of the content of your input message. This is needed to generate the WSDL and invoke the database query with parameters.</p>
<pre><span style="font-style: italic; color: #808080;">// input format array(param_name =&gt; SQL_TYPE)</span>
<span style="color: #0000ff;">$inputFormat</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"customerNumber"</span> =&gt; <span style="color: #ff0000;">"INT"</span><span style="color: #66cc66;">)</span>;</pre>
<p><strong>Output Format</strong></p>
<p>You can customize your response SOAP message by providing the names of the wrapper elements  for both the message and the rows.</p>
<pre><span style="font-style: italic; color: #808080;">// output format, plese check the API from http://wso2.org/wiki/display/wsfphp/API+for+Data+Services+Revised</span>
<span style="color: #0000ff;">$outputFormat</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"resultElement"</span> =&gt; <span style="color: #ff0000;">"Orders"</span>, <span style="font-style: italic; color: #808080;">//the name of the wrapper element of the message</span>
                      <span style="color: #ff0000;">"rowElement"</span> =&gt; <span style="color: #ff0000;">"Order"</span>, <span style="font-style: italic; color: #808080;">//the name of the wrapper element of each row</span>
                      <span style="color: #ff0000;">"elements"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span> <span style="color: #ff0000;">"order-number"</span> =&gt; <span style="color: #ff0000;">"OrderNumber"</span>,
                                           <span style="color: #ff0000;">"order-date"</span> =&gt; <span style="color: #ff0000;">"OrderDate"</span>,
                                           <span style="color: #ff0000;">"status"</span> =&gt; <span style="color: #ff0000;">"status"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p><strong>Create the Query</strong></p>
<p>The query in the PHP dataserivces term is not just the SQL query that you are familiar in accessing a database, It contains the input and output formats in addition to the actual SQL query to invoke.</p>
<pre><span style="font-style: italic; color: #808080;">// sql statment to execute</span>
<span style="color: #0000ff;">$sql</span>=<span style="color: #ff0000;">"select o.OrderNumber, o.OrderDate, o.status from Customers c, Orders o where c.customerNumber=o.customerNumber and c.customerNumber=?"</span>;

<span style="font-style: italic; color: #808080;">// operations are consist of inputFormat (optional), outputFormat(required), sql(sql), input_mapping(optional)</span>
<span style="color: #0000ff;">$operations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"customerOrders"</span> =&gt;array<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"inputFormat"</span> =&gt; <span style="color: #0000ff;">$inputFormat</span>, <span style="color: #ff0000;">"outputFormat"</span> =&gt; <span style="color: #0000ff;">$outputFormat</span>, <span style="color: #ff0000;">"sql"</span> =&gt; <span style="color: #0000ff;">$sql</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p><strong>DataService object</strong></p>
<p>Finally you create the DataService object with the provided configurations and the query information.</p>
<pre><span style="color: #b1b100;">require_once</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"wso2/DataServices/DataService.php"</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$my_data_service</span> = <span style="font-weight: bold; color: #000000;">new</span> DataService<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"config"</span> =&gt; <span style="color: #0000ff;">$config</span>,<span style="color: #ff0000;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$my_data_service</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/06/php-dataservices-2-minutes-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install PHP, WSF/PHP and DataServices in a Shared Hosting Environment</title>
		<link>http://www.dimuthu.org/blog/2008/08/16/install-php-wsfphp-and-dataservices-in-a-shared-hosting-environment/</link>
		<comments>http://www.dimuthu.org/blog/2008/08/16/install-php-wsfphp-and-dataservices-in-a-shared-hosting-environment/#comments</comments>
		<pubDate>Sat, 16 Aug 2008 07:55:00 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[cgi]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[dreamhost]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[lamp]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php.cgi]]></category>
		<category><![CDATA[php.ini]]></category>
		<category><![CDATA[Shared hosting environment]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=123</guid>
		<description><![CDATA[If you have a shared hosting environment you will find it is not straight forward to install WSO2 WSF/PHP + PHP DataServices Library since you have very limited authority on your environment. Here in this post, I&#8217;m explaining the steps I followed in setting up my custom PHP, WSF/PHP Extension and DataServices library for http://ws.dimuthu.org [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a shared hosting environment you will find it is not straight forward to install <a href="http://wso2.org/projects/wsf/php">WSO2 WSF/PHP</a> + <a href="http://labs.wso2.org/wsf/php/resource_view.php?url=DataServices">PHP DataServices Library</a> since you have very limited authority on your environment. Here in this post, I&#8217;m explaining the steps I followed in setting up my custom PHP, WSF/PHP Extension and DataServices library for <a href="http://ws.dimuthu.org">http://ws.dimuthu.org</a> (This is a shared hosting environment from <a href="http://dreamhost.com">dreamhost</a> based on LAMP stack) which I&#8217;m using to expose my blog as a WebService.</p>
<p><strong>Prerequisites:</strong></p>
<ol>
<li>You should be able to run PHP using mod_fastcgi (not using mod_php) in Apache. That allows you to configure your own php environment.</li>
<li>The server configurations managed by the hosting service should allow you to handle .php extension from your own  CGI executable (here it is php.cgi), If not, you can still try with setting some other extension (say .phq or .qhq, anything not .php) to be handled by your php-cgi. Anyway if your hosting service allow you to run CGI then most probably you have this permission.</li>
<li>You should have the access to the shell (using SSH) and should be able to use development libraries(libxml, libxsl, libopenssl) + build tools (make)</li>
<li>There can be some other restrictions that your hosting service has put on you, that I have not experienced with my hosting service. So please check your hosting service support and documentation for possibility of building your own PHP environment.</li>
</ol>
<p><strong>Install PHP:</strong></p>
<p>I have extracted out most of the steps from <a href="http://wiki.dreamhost.com/Custom_PHP.ini">dreamhost documentation on custom php.ini.</a></p>
<ol>
<li> <a href="http://php.net">Download PHP</a> and compile. You should at least enable &#8211;enable-fastcgi &#8211;enable-force-cgi-redirect in the configuration.
<pre>./configure --enable-fastcgi --enable-force-cgi-redirect --with-xsl --with-openssl --prefix=`pwd`/dist
make
make install</pre>
<p>Note: from here on, php source directory is referred as &lt;php_source_directory&gt;<br />
I have installed the php to &lt;php_source_directory&gt;/dist since we mostly don&#8217;t have permission to install it in to default location. (/usr/local). From here on I will be referring php installation directory as &lt;php_install_dir&gt;</li>
<li>create a directory called &#8216;cgi-bin&#8217; to your web document root directory(&lt;document_root_directory&gt;) and copy the &lt;php_source_directory&gt;/dist/bin/php-cgi in to that. (before php version 5.2.1 there is no php-cgi generated, you can just copy the php to the cgi-bin directory). And rename the php-cgi to php.cgi.
<pre>cp &lt;php_install_direcory&gt;/bin/php-cgi &lt;document_root_directory&gt;/cgi-bin/php.cgi</pre>
</li>
<li>copy &lt;php_source_direcory/php.ini-dist to the cgi-bin directory and rename it as php.ini, this can be used to configure your php environment.
<pre>cp &lt;php_source_directory/php.ini-dist &lt;document_root_directory&gt;/cgi-bin/php.ini</pre>
</li>
<li>Create .htaccess file in the cgi-bin directory to allow the access to php-cgi and php.ini files.
<pre><span style="font-weight: bold; color: #c20cb9;">cat</span> &lt;&lt; EOF &gt;&lt;document_root_directory&gt;/cgi-bin/.htaccess
Options +ExecCGI -Indexes +FollowSymLinks
&lt;FilesMatch <span style="color: #ff0000;">"php(.?)<span style="font-weight: bold; color: #000099;">\\</span>.(cgi|ini)$"</span>&gt;
Order Deny,Allow
Deny from All
Allow from <span style="color: #007800;">env=</span>REDIRECT_STATUS
&lt;/FilesMatch&gt;

EOF</pre>
</li>
<li>Create .htaccess file in the root directory redirect all the requests for .php extensions to go through our php-cgi.
<pre><span style="font-weight: bold; color: #c20cb9;">cat</span> &lt;&lt; EOF &gt; &lt;document_root_directory&gt;/.htaccess
AddHandler php-cgi .php
Action php-cgi /cgi-bin/php.cgi
EOF</pre>
<p>If your hosting service doesn&#8217;t allow to handle .php just rename the end of the first line to some other extension.</li>
<li>Check the necessary permissions levels in files.
<pre>chmod 644 &lt;document_root_directory&gt;/.htaccess
chmod 755 &lt;document_root_directory&gt;/cgi-bin
chmod 644 &lt;document_root_directory&gt;/cgi-bin/.htaccess
chmod 644 &lt;document_root_directory&gt;/cgi-bin/php.ini
chmod 755 &lt;document_root_directory&gt;/cgi-bin/php.cgi</pre>
</li>
</ol>
<p>That&#8217;s it. Now your .php files should be run on your own php environment. Just to check whether it is working or not create a phpinfo() file.</p>
<pre><span style="font-weight: bold; color: #c20cb9;">cat</span> &lt;&lt;EOF &gt; phpinfo.php
&lt;?php
phpinfo<span style="font-weight: bold; color: #7a0874;">(</span><span style="font-weight: bold; color: #7a0874;">)</span>;
?&gt;
EOF</pre>
<p>And go to the http://yourdoman.com/phpinfo.php and verify that it is your custom php environment .</p>
<p><strong>Installing WSF/PHP</strong></p>
<ol>
<li><a href="http://wso2.org/downloads/wsf/php">Download WSF/PHP latest version</a> and extract it to any of your preferred directory(&lt;wsf_php_source_directory&gt;).</li>
<li>Set the PATH environment variable to search for your custom php installation first.</li>
<pre>export PATH=&lt;php_install_dir&gt;/bin:$PATH</pre>
<li>From the same shell go to the &lt;wsf_php_source_directory&gt; and compile it.
<pre>./configure
make
make install</pre>
</li>
<li>Now check where you have installed wsf/php. it is in fact the extension dir shown by the php-config command.
<pre>php-config --extension-dir</pre>
<p>I will refer this directory as &lt;php_extension_directory&gt;</li>
<li>Open the &lt;document_root_directory&gt;/cgi-bin/php.ini an set the extension directory, enable wsf extension and set the include path to the wsf scripts directory.cat &lt;&lt;EOF &gt;&gt; &lt;wsf_php_source_directory&gt;/cgi-bin/php.ini
<pre><span style="font-weight: bold; color: #c20cb9;">cat</span> &lt;&lt;EOF &gt;&gt; &lt;wsf_php_source_directory&gt;/cgi-bin/php.ini
<span style="color: #007800;">extension_dir=</span>&lt;php_extension_directory&gt;
<span style="color: #007800;">extension=</span>wsf.so
<span style="color: #007800;">include_path=</span><span style="color: #ff0000;">".:&lt;wsf_php_source_directory&gt;/scripts"</span>

EOF</pre>
<p>If you found that you can only put relative directories in your php.ini (that happens when you don&#8217;t even have the read access to your root directory &#8216;/&#8217;), follow the workaround mentioned in here, <a href="http://phpwebservices.blogspot.com/2008/08/installing-wsfphp-in-third-party.html">http://phpwebservices.blogspot.com/2008/08/installing-wsfphp-in-third-party.html</a></li>
</ol>
<p>That&#8217;s all. Just check the phpinfo (created earlier section) whether your configurations and the wsf extension are loaded correctly. In order to test the functionality copy the wsf/php samples to the web document root and access them from the browser. Go to each sample and verify they function as expected.</p>
<pre>cp /samples &lt;wsf_php_source_directory&gt;/ -R</pre>
<p>And go to http://yourdomain.com/samples and click on each samples. If this not working most probably your localhost to ip mapping is wrong, most probably this problem is there in your shared host. Just go to the samples directory and change the endpoint to the domain name in place of &#8216;localhost&#8217; in each client and try it again.</p>
<p><strong>Installing PHP DataServices</strong>:</p>
<ol>
<li><a href="http://labs.wso2.org/wsf/php/resource_view.php?url=DataServices">Download and unpack PHP DataServices</a>. &lt;php_data_services_directory&gt;</li>
<li>Update the include_path entry in php.ini to DataServices libraries directory as well. So the &lt;wsf_php_source_directory&gt;/cgi-bin/php.ini  file now has the following entry.
<pre>include_path=".:&lt;wsf_php_source_directory&gt;/scripts:&lt;php_data_services_directory&gt;/lib"</pre>
</li>
</ol>
<p>That&#8217; all for the DataService installation. Please read &lt;php_data_services_directory&gt;/README to run the samples. Anyway if you are sure you did followed these simple steps correctly, go on with your DataService  development. Specially if you have wordpress database, you may start straight away with<a href="http://www.dimuthu.org/blog/2008/08/11/make-your-wordpress-blog-a-web-service-in-few-step/"> the making wordpress a DataService</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/08/16/install-php-wsfphp-and-dataservices-in-a-shared-hosting-environment/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

