PhpED: PHP IDE
new features
features
version comparison
features: php tools
php debugger
php profiler
php frameworks
php scripts
features tour
licensing
php testing
PhpED difference
PhpED on Mac/Linux
testimonials
PhpDock
Nu-Coder
PhpExpress
TechPlatform

Ajax PHP Database Form

Ajax, PHP and Database make a great combination for producing Web based ecommerce applications. Ajax based asynchronous calls to PHP scripts on the back end implement Model View Controller architecture and allow the developer to separate the presentation layer from the business logic. Ajax PHP Database
NuSphere's DB-Form Wizard comes just at the right time with its templates and macro substitution mechanism vastly improved in PhpED 5.0 to make Ajax PHP programming for the database as easy as making 8 clicks on the DB-Form Wizard menus.

How to use Ajax PHP Database template

Ajax PHP Database template files are located in plugins folder of PhpED installation. Presentation layer with Ajax calls is implemented in ajax_db_form.phpt template file and back end database connection logic is implemented in table_actions.phpt template. Ajax PHP Database Styles
dbwizard.ini configuration file contains the description of Ajax-Sort-Browsing style, which is picked up by Db-Form Wizard and made available for the selection on Styles page:

To generate Ajax-Sort-Browsing PHP Database form you should select Ajax-Sort-Browsing style and save the scripts generated by Db-Form Wizard the same way as it is decribed on PHP MySQL page or follow the instructions in PhpED manual. Once the files are stored, you can execute ajax_db_form.php - the output of ajax_db_form.phpt. The form generated by this script will display the records in the selected database table and provide the Ajax based User Interface to navigate through the data in the table, insert, delete and update the records and sort them by columns.

How is Ajax implemented in php script generated by DB-Form Wizard

Ajax calls to PHP back end are implemented in ajax_db_form.phpt template file, which generates ajax_db_form.php script. If you take a brief look at ajax_db_form.phpt you will notice that there are only a few lines of PHP code after the line
$fielddef = @@FIELDDEFS@@;

@@FIELDDEFS@@ is a DB-Form Wizard macro, which gets substituted with the Array representing the schema of the selected table as described in PHP Database tutorial. PHP code is located in the presentation layer for one and only purpose: to initialize the validation of the fields using $fld_indices_<type of validation> strings, which are later used in CheckForm() Javascript function. The illustration of this is shown below using PHP Debugger Ajax PHP Database in Debugger
The rest of ajax_db_form.phpt is pure HTML and Javascript code. Ajax request initialization is implemented in getAjaxRequest() Javascript function, which is called by
  • ajaxFunctionUpdateInsert() - to request the interface for Update or Insert of the records
  • ajaxFunctionDelete() - to request the deletion of selected record
  • ajaxFunctionForm() - to request the sorting of a given column or navigate to a different page of the records table
Ajax's onreadystatechange() call results in the call to replaceDivElements() Javascript function, which puts in place the output produced by the back end PHP script.

How is database connection implemented by PHP back end script

Ajax calls to PHP back end are handled by the PHP script generated by table_actions.phpt template. The name of the resulting PHP script is created using selected table name, for example table_items.php. This is done with the help of @@TABLENAME.ALPHANUM@@ macro used in the name of the second of the targetfiles for table_actions.phpt.

The code in table_actions.phpt consists of 4 functional areas:
  • initialization the database table records
  • processing of select, insert, delete or update request - depending on the type of Ajax request made by the form
  • dependant on the type of the request producing of
    • the form for insert of the record
    • the form for update of the record
    • perform deletion of the record and produce the output with the records in the table
    • output of the records in the table base on the start page and sorting request
  • producing the header buttons and the pager links with the calls to Ajax Javascript functions described above.
PHP Database backend script uses the same fields definition macro $fielddef = @@FIELDDEFS@@; to initialize the array of the records. After that the processing of the request is done with the switch by the mode to select, insert, update or delete the record. All database calls are encapsulated in dbconn PHP class implemented in db_utils.inc file installed in include_lib folder of PhpED. The figure below illustrates the processing of the Ajax request to select the records from the database table: Ajax PHP Database Select
You will notice, that the output HTML for the pager and the header contains the calls to ajaxFunctions described above, as it is shown here: Ajax PHP Database Links

As you can see, the macros mechanism used by Db-Form Wizard gives you the full flexibility to create your own templates for PHP Database Forms, using Ajax or PHP Smarty or any other of the PHP Frameworks. Download a free trial of our PHP IDE with Ajax PHP Database form today!

 Download NuSphere PHP IDE

Download a free trial of the fast PHP EDitor and robust Integrated Development Environment for PHP.

 Buy NuSphere PhpED® now

Best PHP Editor and complete PHP IDE.
NuSphere PhpED 20.0 is available from our online store front.
"To be honest its bloody awesome, I have looked at loads of PHP editors and this is THE only one that actual works straight out of the box!!! Brilliant, well done."
Andrew Breward,
Director of Technology
caboodal.com

 Guide

Walk through NuSphere PhpED interface
PhpED video tutorial: Webservices
Learn how to add webservices to your code in less than 5 minutes (a flash demo).

 Special Team4 Offer

Get 4 copies of PhpED for the price of 3!

Optimum solution for development teams.
PhpED 20.0 Team4
Need more than 4 licenses? Contact Us for more quantity discounts, please use "Ordering/Payment issue" subject on the form.

 Dr. Dobb's

Dr. Dobb's

Dr. Dobb's Magazine covers NuSphere PhpED in New and Noteworthy section.

 InfoWorld

infoworld.com
PhpED is a proper, world-class IDE for PHP code. It is the only IDE worth considering if PHP development is your primary job