Creating a database application

The flash builder have a superb feature called Data Service which provide the server integration functionality. Thus, flash application can contact the server database.  This gives opportunity to develop high secure application like login systems. Also by using server database systems, we can create database reports in chart format or data grid formats, Updating or adding of records to the database or we can create multiplayer games. So I think now you can realize the significance of Data Services.

The data services can be accessed in flash builder by service calls. The return type can be any format (like object, integer, string). The accessible data services are ColdFusion services, AMF-based PHP services, BlazeD , LiveCycle Data Services. The server type may be PHP, ColdFusion or J2EE.  Programming the service calls for this kind is very simple with the Wizard procedure in the Flash Builder. In addition, you need to know is only few parameters, not all technical details about the server systems.

Now let us see an example of creating an Application, which capable of accessing the MySQL database of the server using the PHP. Amazing fact is that for trying this you do not need to know about the PHP Programming. However, PHP coding is essential at this case to access the database; the Flash builder will accomplish this work. That it will write the essential function in PHP codes to access the database. Since, we need different types of codes according to database structure. During creation if you point out the location of database. Then it will optimize the PHP coding to fit for the database.

For trying out this you need a virtual web server application with MySQL and PHP, I suggest using the EasyPHP software. I have used the EasyPHP in this example, so I think the following procedure will not confuse you in between. Before using the data services, you must to install the EasyPHP or any other equivalent software that does it functions like WAMPP.

Step 1:

After installing the virtual web server in your system, we need a database with a table with some datum to work with data retrieval example. Following table is an sample table we are going to create with the MySQL commands.






















To create the above table, with database name as ‘contacts’ and table name as ‘biodata’, just follow the procedures below.  

  1. Navigate to (

Click on SQL Query Window Icon which will be located below phpMyAdmin logo as 2nd from left side

Then the SQL query window will appear like below. This window is for running the SQL commands. Just all that you need is to type the code and click GO to execute it

I have given the SQL command codes to create the sample table I given above. By just typing this code a database table will be created in the server for our application. After typing code and executing it, you will get a message that “Query Executed Successfully” which means table creation is successful and we can proceed to next step.

CREATE DATABASE `contacts` ;
USE `contacts`;
CREATE TABLE `biodata` (`No` INT( 5 ) NOT NULL ,`Name` VARCHAR( 20 ) NOT NULL ,`Age` INT( 2 ) NOT NULL ) ENGINE = MYISAM ;
INSERT INTO `biodata` ( `No` , `Name` , `Age` ) VALUES ('37', 'Parthiban', '19'), ('14', 'DineshBabu', '20');
INSERT INTO `biodata` ( `No` , `Name` , `Age` ) VALUES ('20', 'Bakeerathan', '17'), ('12', 'Thangarajan', '51');
INSERT INTO `biodata` ( `No` , `Name` , `Age` ) VALUES ('22', 'Mareeswari', '47'), ('12', 'Gowtham', '15');

Step 2:

Now create a new Project form the File > New > Flash Project.  Create the project as per the normal procedure as mentioned in the earlier article .Now when you have opened the coding environment, now navigate to Data > Connect to Data/Service

It will invoke the Connect to Data/Service wizard that will show a list of data service Select the PHP service for our application and click “NEXT”

Step 3:

Then if you have mentioned the server at the creation of this project then you will get inside it, by skipping some steps. In this we didn’t mentioned that at the creation of this project thus it will ask a message like below

Click “Yes” and proceed to Properties windows configurations

Step 4:

Now select the server type as PHP and other detail of server location like Web root(“C:\Program Files\EasyPHP 2.0b1\www”) and root url ( are default values for the EasyPHP, the web root location will change for the other servers application like WAMPP. Finally, after entering the values do not forget to press “Validate Configuration” button.

When the validation button is pressed, it will check the configuration. Once the validation successful you can find that, the “Apply” and “OK” button will be enabled. Now click Ok to proceed. Then another window will appear which will ask for the PHP Class name and other service details.

Step 5:

In which click on the “Click here to generate a sample”.It will ask for a message like below

The Zend Framework is a collection of PHP service function which have lot of functionalities. Click OK to install it on the webroot, it will take a space upto 20 MB on your server

Step 6:

Now it will open the Generate PHP Sample Service window, in which give the User Name, which is default as “root” and leave the password as blank if you have not set. Provide the value for Host name as “localhost” and server port value as 3306 (default for the SQL server). The name of the database we created is “contacts” give that name too. Now click on “connect to database” and wait

Now the table list will appear in which our table name bio data wlll be displayed, select it from the list. Then the primay key list will show the fields available select the No field as Primary key and click OK.

A warning message will be displayed. Since we are doing for the test purpose only no need to worry about just click Ok and proceed to next step

Step 7:

Then it will return to the previous window with the fields filled ie. Now it have created a php file name Biodataservice.php which will have necessary function to access the SQL database list.

Step 8:

Now it will show the available function on the PHP file created. Just look and click Finish.

Step 9:

Now you can see in the bottom of the screen showing the BiodataService in the Data/Services tab. For a testing if want to check the function ‘count()’ without using the programming you can just right click it and select “Test operation”. Actually the count function of PHP count the no of records in the database.

This helps in testing the function without actually using it in the programming, it also show the return value from a particular function

Now on the left side of the screen the Test Operation tab will be opened in which if you press the “Test” button, it will call the particular function and it will show the return type as “Response name” and return value as the “Response value”

Similar case if you have selected the getallBiodata() function and given the Test Operation. Then it will return all records like shown below

Step 10:

                Now let us see how to bind these values in the components. Binding of this value to the components is very easy than you expect to be. Now take in case of example if you want to show this record in the data grid.

  1. Insert a data grid on the Design Mode.
  2. Now drag and drop the getallBiodata() function from the “Data/Service” tab at bottom to data gid
  3. Now a small “bind” icon will appear & the column name wil be changed to field names of database

Now run the program you will find all the records will be arranged in the data grid.

Step 11:

Now let us see how to create Delete record option. For this create a button with text “Delete”. Right click on it and select Generate Service Call. It will show a window in which select the Operation as “deleteBiodata(ItemID : int): void”.

Now it will bring you inside a function and it will ask for the ItemID value, give it as “dataGrid.selectedItem.No”.

Step 12:

 If you want to create the form for adding the new records the SQL Database, just right click on the “createBiodata(item : Biodata) : int” function under the Data/Service tab and select generate form

The generate form will appear in which select only the “Form for input parameters” and uncheck the form for return type. This is because we want form only for adding the data to table and a form for showing successful operation is not required. Now click Next.

Now it will show a list of available fields select them all and click finish. Now the form will be created on the design. In the run time, you can enter the data for the field and press CreateBiodata button to add record.

Similarly, you can create form like this for updating the records. For which right click on the update function under the data service tab and Click on Generate Form.