Broadcast on Broadcast off
The Documentation for Project Zero has moved. Please update your bookmarks to: http://www.projectzero.org/documentation/

PHP data access example

This example uses a simple TODO list to demonstrate how to access a database using PHP. The application is included with the Zero Examples plugin. The following steps show how to access the example:

  1. From the File menu, click New > Example...
  2. Click Zero Examples > Project Zero Example Projects.
  3. Check the box next to PHP Data Access. A new project named PHP.Data.Access is created in your workspace.
  4. This example can use either Derby or MySQL as the database. The README.txt file found in the root of the project explains how to enable the two configurations.

Once the application setup is complete, launch the application by right-clicking the project, Run As > Project Zero Application. A successful launch should display the following string in the Console view: "...\PHP.Data.Access running on port 8080". Now open your browser to http://localhost:8080/index.html. Your screen should look like the following snapshot.

PHPDataAccessExample1.JPG

The following table explains how the various user actions are handled by the application.

User action HTTP method URL Handler file (under /app/resources) Notes
"Item ID" link GET http://localhost:8080/resources/todoitems/{id} todoitems.php Returns the item contents as JSON.
"Mark as Complete" button PUT http://localhost:8080/resources/todoitems/{id} todoitems.php Marks the item as completed by setting the value of the 'completed' column to 1.
"Remove" button DELETE http://localhost:8080/resources/todoitems/{id} todoitems.php Removes the item from the database table.
Page load GET http://localhost:8080/resources/todoitems todoitems.php Returns all items in the list as JSON.
"Create" button" POST http://localhost:8080/resources/todoitems todoitems.php Creates a new item which will have an id assigned by the database.

r4 - 12 Sep 2007 - 14:11:07 - csurface
Syndicate this site RSS ATOM
Copyright 2007 © IBM Corporation | Privacy | Terms of Use | About this site