You can generate an application that uses PHP and a MySQL database. To generate this type of application, you must have a local PHP server and access to a target MySQL database table.
Generate PHP application code
1. If you have not already done so, create a Flex project that specifies PHP as its application server type.
2. Select Data > Create Application from Database.
3. From the Project list, select the PHP project to use.
4. From the Connection list, select a database connection profile. To create and use a new connection profile, click the New button and complete the text boxes. For more information, see Directory structure and deployment considerations for PHP.
5. From the Table list, select the database table to use.
6. From the Primary Key list, select the primary key of the database table if it is not already selected.
7. Click Next.
8. Specify a Main Source Folder and a Main Application File, or accept the default values. You can generate the PHP files in the bin-debug folder, which is the default location, or in the src folder. If you want to export the project after using the data wizard, you must generate the PHP files in the src folder; otherwise, the project is exported without the PHP files and does not function.
9. Click Next.
10. Deselect any database columns that you do not want to appear in the DataGrid that the wizard generates.
11. Choose a database filter column, or accept the default value.
12. Click Finish.
13. Select Run > External Tools > Run As > Run on Server.
14. Select Run > Run to run the application on the server.
Directory structure and deployment considerations for PHP
When you use the data wizard to generate a PHP application, the default location of the generated files is the [web_server_root]\[project_name]_debug directory. The directory includes a PEAR subdirectory that contains the PEAR XML parsing utility, and a history subdirectory that contains files for Flex history management.
The main deployment directory contains tablename.php, databasenameconn.php, functionsinc.php, and XmlSerializer.class.php PHP files. It also contains a SWF file named tablename.swf and an HTML wrapper named tablename.html.
The project src directory contains the following files: tablename.mxml, tablenameconfig.as, and tablenamescript.as.
Deploy an application to a remote server
1. Set up the host:
1. Create a new database. Typically, the host has a naming convention like sitename_dbname.
2. Create a web user with a password (for example, name: bigryans_webuser, pw: webuser). Give the web user the following privileges: insert, update, delete, and select.
3. Create the database table or tables (you can export the SQL and run it in your MySQL administrator application, or you can create it manually); for example:
CREATE TABLE users (
userid int(10) unsigned NOT NULL auto_increment,
username varchar(255) collate latin1_general_ci NOT NULL,
emailaddress varchar(255) collate latin1_general_ci NOT NULL,
PRIMARY KEY (userid)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
2. Edit the Flexphpconn.php file. This file creates the connection to the database for your Flex application users:
$hostname_conn = "localhost"; // If your database and Flex app are on the same server $database_conn = "bigryans_flexphp"; // name you gave it in step 1 $username_conn = "bigryans_webuser"; // name you created in step 1 $password_conn = "webuser"; // password you gave it in step 1
3. Upload the files. You need the following subset of the files that the wizard outputs:
* /history directory (if you want to support history management/deep linking)
* /PEAR directory
* AC_OETags.js
* Flexphpconn.php
* functions.inc.php
* playerProdInstall.swf (if you want to support express installation)
* Flex application files:
o users.html (HTML wrapper)
o users.swf (Flex application)
o users.php (PHP functions for the Flex application)
o XMLSerializer.class.php
You do not need to upload the xxx-profile.swf files, the projectname.swf file, or the projectname.html file.
No comments:
Post a Comment