Delphi/400 for PHP Tutorial

By: Tim DelChiaro

Abstract: Building your first application using Delphi/400 for PHP



This tutorial from SystemObjects will help you get started using Delphi/400 for PHP.

Versions used:

  • i5/OS V5R4
  • Delphi/400 for PHP 1.0
  • PHP 5

All the files used by this tutorial are:

  • In the system I library named “CO409”
  • In your installation drive of your PC under the “Delphi/400 for PHP Tutorial” folder

For the installation of the product, please make sure to install first the Delphi for PHP license before our software.

This tutorial will cover the following points:

  1. Configuration of the System i alias,
  2. Configuration of the ODBC alias,
  3. The first PHP application to display rows of a System i table,
  4. How to add a graphic HTML page to the first application,
  5. The other components with our examples.

1. Configuration of the System i alias.

Start the Delphi/400 for PHP configuration.

Hide image

You get this image:

Hide image

Click on the right the “Add” button:

Hide image

Enter a name “D400PHP” for your alias, the IP address of your System i, the port number (must be 27003), choose your code page and select the SystemObjects’ library, “CO411”.

To verify your installation and your configuration you can click on the “Apply and

Test Connection” button.

On this configuration tool, you can see two important tabs:

  1. “DLL Information” is a list of installed software on your PC, it’s easier to send it to the support in case of requests,
  2. “Update from the Web”, is an easy solution to get the last version of your software directly from our support web site.

2. Configuration of the ODBC alias

To create the ODBC alias you will use the standard ODBC Data Source Administrator.

You must start the “Control Panel” and choose the “Administrative Tools”, then double click on the ODBC Data Source Administrator.

Select “System DSN’ (the second tab on the top) and you will have this picture:

Hide image

Click the “Add…” button.

Choose the “SystemObjects ODBC PHP Driver “on the list by double click.

On the form of the next page you can fill:

  • The name of your alias, “SYSTEMIPHP” in our example,
  • You must choose the System i alias in the combo box “System”,
  • The Default User ID and Password if you want,
  • Choose the Naming Convention for SQL statements,
  • And the Library Option.

You will have the following image:

Hide image

Click “Apply” and next “OK”.

3. Your first PHP application to display rows of a System i table.

Start Delphi for PHP.

Hide image

You get this:

Hide image

Click on the “New” button or on the menu File to create a new application like this:

Hide image

You get a blank form.

On the bottom right of your screen there is the “Tool Palette”.

On the palette choose the “SystemObjects DB” group of components.

Select the SODatabase component and drag it to your form.

Hide image

Do the same for the SOQuery and the SODataSource components.

You have this image:

Hide image
Click to see full-sized image

We are going to use the object inspector to set up the properties for the three components.

Select the Database component on your form.

Type the name of your ODBC alias in the “Host” property.

You have this image:

Hide image

Now select the Query component.

Open the Database property combo box and choose the “SODatabase1”, it’s the name of your data base component if you don’t change it.

Select the SQL property and in the new window input this select instruction:

select * from co411.customer”.

You have this image:

Hide image

Next select the Datasource component.

Open the DataSet property and select SOQuery1, the name of your Query component.

To display the records select the “SystemObjects CTL” on the tool palette.

Then choose the “SODBGrid” object and draw a small rectangle on your form

like this:

Hide image
Click to see full-sized image

The DBGrid object is selected.

Now in the object inspector select the “Datasource1” in the combo box of the DataSource property to make the link between this grid and your data source.

Now on select the form and on the Object Inspector select the “Events” tab.

Double click the “OnBeforeShow” event and enter the three lines to set your System i UserID, the password and to open the Query.

It’s finished.

Hide image
Click to see full-sized image

Save your project and run it using the “Green” arrow image032 on the tool bar.

This Internet Explorer works with the local Apache server included in Delphi/400 for PHP.

You get this image:

Hide image

To deploy your application on your production server, click on the menu

Tools > Deployment Wizard:

Hide image

And select the path of your Apache server in the next screen.

In our example it’s on my local PC

Hide image

Click the Next button.

To run you application type http://your_host_name/firstapp.php.

In our example it’s my local PC on the port 81 and I used the name “firstapp.php” for my application.

And you get this:

Hide image

4. How to add a graphic HTML page to your first application.

With standard PHP development environment you need to add all HTML tags in your code, something very long. With Delphi/400 for PHP you can “integrate” your application in a pre-built HTML page and that’s all.

First of all you must create your HTML page with the tool of your choice. You can use all exiting HTML components, all HTML features, there are no limits about the design of your page.You can use also “css” cascading style sheet to enhance the presentation of your information.

When you finish the design of your page, you need to add special tags in your HTML file to explain Delphi/400 for PHP where it will include your applications objects.

The first tag to add is:


This tag is added on the top of your file like this:

<title>Delphi/400 for PHP - First Application</title>
<link href="demo.css" rel="stylesheet" type="text/css" />

Next you need to explain where you want to start your form using the



You can put this tag also in the top of your file like this:

<table width="74%" cellspacing="0" cellpadding="0">

And at the end of your HTML page you need to add the {EndForm} tag.

You can put it at the bottom of your file like this:


Now for each Delphi/400 for PHP component of your application (displayed in your HTML page) you must include a tag with its name on the cell where you want to present it on your form.

This name must be prefixed by the $ sign.

If your component (our grid for example) is named “grid”, you need to add a tag {$grid} on one cell.

In the Delphi/400 for PHP IDE select the grid component and in the object inspector input the name “grid” to the “Name” property:

Hide image

The grid object is selected and you input the name “grid” in the name property.

You need to do the same operation for all the components displayed in the HTML page.

Now you select your form, the background of your application to make a link between this application and your HTML page.

When the form is selected, the name of your form is displayed on top of the object inspector, select the property “TemplateEngine” and in the combo box select “SmartyTemplate”.

Next on the property “TemplateFileName” input the name of your HTML page, or browse your directory to find it, in our example the name of our page is demo.html in the Delphi400 for PHP Tutorial directory.

You have this image:

Hide image

And that’s all. You can run your new application just with a click on the Green button and you get this:

Hide image

When you publish your new application to the production web server, don’t forget to copy all your HTML file, CSS files, images, subfolders…

5. The other components with our examples.

For each of our component you will find a project with a small example.

These projects are stored as subfolders in the installation directory.

Hide image

The list of all our examples installed on your PC.

© SystemObjects

Server Response from: ETNASC04