PHP examples

Do not run this file locally
Run it from your (local) web server where is installed your http server like IIS or Apache and PHP 4.x/5.x.

The PHP service program must have write access to all files in folder /Examples/Php/Database
To permit write access on Windows XP right click to folder Database in My Computer, select Properties -> Security -> Users and set Full control to Allow. If you don't have Security item in Properties, run My Computer, in menu select Tools - > Folder options -> View and uncheck Use simple file sharing option.

All the examples use SQL database in text files (PHP Text DB). The PHP core files for txt database are located in /php-txt-db-api directory. The database is located in directory /Database where are stored tables as individual txt files.
For database access are used objects Database and Recordset defined in IncDbTxt.php file. You can change database provider to other (odbc,ado,sqlite) by including other IncDb...php file and changing connection string when creating Database object.


PHP 4 and 5


Ajax

Asynchronous background (new style) communication with server.
Data are downloaded from or uploaded to server by JavaScript XmlHttpRequest object on background, without reloading/submitting the page content.
You can check from configuration menu option Auto update changes to server for immediate updates after edit/modify.
When debugging, you can set <treegrid ... Debug='3' ... > to see communication with server. It opens two new browser's windows. You can see XML data or PHP error server returned.
Remember, in Ajax communication, the php page must return only xml data, not any standard html tags like <html> or <!doctype>.
See documentation AJAX versus submit and also tutorial Identifying rows when uploading.

Ajax table
Main file AjaxTable.html, support code AjaxTable.php
Layout file in TableDef.xml, data in database table "TableData".
The simplest demonstration of using ASP and AJAX. It generates data from database table 1:1 including id. Also updates changes to database according/with id.

Ajax table with framework
Main file AjaxTableFramework.html, support code AjaxTableFramework.php, framework code TreeGridFramework.php
Layout file in TableDef.xml, data in database table "TableData".
The same example as previous Ajax table but with using functions from TreeGrid ASP Framework. Also shows using user parameters.

Ajax table with server side paging and export
Main file AjaxTablePaging.html, support codes AjaxTablePaging.php , AjaxTablePagingPage.php , AjaxTablePagingExport.php
Layout file in TableDef.xml, data in database table "TableData".
The same example as previous Ajax table but with using server paging and export routine.
The pages are downloaded on demand from server (when the page is visible by scrollbars).
It is simple example with ineffective database access - it loads all table for every page and throws the rest away.
It also simply reloads all body when rows are added or deleted instead of handling changes in pages.

Ajax tree with framework
Main file AjaxTreeFramework.html, support code AjaxTreeFramework.php, framework code TreeGridFramework.php
Layout file in TreeDef.xml, data in database table "TreeData".
Generates treetable from database table with column Parent where are relations Parents/Children. Parent column contains parent's id of the child. For root rows it contains "#Body", for fixed rows "#Head" or "#Foot".
Uploaded rows are still identified by preset and standardly generated id attributes.
Uses functions from TreeGrid ASP Framework.

Ajax Extended API with reloading
Main file AjaxAPI.html, support codes AjaxTableFramework.php and AjaxTreeFramework.php , framework code TreeGridFramework.php
Layout files in TableDef.xml and TreeDef.xml, data in database tables "TableData" and "TreeData".
It shows two tables from previous examples and demonstrates Extended API functions for reloading, changing data source when reloading, catching data event and so on.

Ajax grid
Main file AjaxGrid.html, support codes AjaxGridData.php , AjaxGridLayout.php , AjaxGridUpload.php
Data in database table "TableData".
Demonstrates advanced generating from and updating to database.
Generates treetable from standard database table. Also flips the table and shows data in changed layout.
For every action is used another support code (Layout, Data, Upload). The layout is also generated.
Rows are identified by one unique editable column, with using full ids (including parents ids).
For demonstration it shows id column, to see what ids are generated by TreeGrid.

Complete application - Schools
Main file Schools.html
Support codes Schools.php (main file generates data and also saves changes to database or adds new user),
SchoolsRatings.php (loads reviews for given record, used for server child paging),
SchoolsReview.php (saves one review to database, called as custom AJAX call).
Layout file in SchoolsDef.xml, data in database tables "Schools_Schools", "Schools_Ratings" and "Schools_Users".
Uses also file SchoolsStars.gif ()
Complete application to demonstrate generating from and updating to different database tables with various structure. Demonstrates also server child paging feature (loading children on demand). And also custom AJAX call.
The application show list of schools that can be sorted and filtered. The records can be added/deleted or modified by logged user or admin. The records can be rated and reviewed by visitors.



Submit

Synchronous (old style) communication with server.
Data are included in page in hidden input. Changes are sent to server in the hidden input of submitted <form> on page.
See documentation AJAX versus submit and also tutorial Identifying rows when uploading.

Submit table
Main file SubmitTable.php
Layout file in TableDef.xml, data in database table "TableData".
The simplest demonstration of using ASP and standard page submit. It generates data from database table 1:1 including id. Also updates changes to database according/with id.
The code is nearly the same as in Ajax table.

Submit table with framework
Main file SubmitTableFramework.php, framework code TreeGridFramework.php
Layout file in TableDef.xml, data in database table "TableData".
The same example as previous Submit table but with using functions from TreeGrid ASP Framework.

Submit tree with framework
Main file SubmitTreeFramework.php, framework code TreeGridFramework.php
Layout file in TreeDef.xml, data in database table "TreeData".
Generates treetable from database table with column Parent where are relations Parents/Children. Parent column contains parent's id of the child. For root rows it contains "#Body", for fixed rows "#Head" or "#Foot".
Uploaded rows are still identified by preset and standardly generated id attributes.
Uses functions from TreeGrid ASP Framework.
The code is nearly the same as in Ajax tree.


PHP 5


Ajax and DLL/so

PHP code uses TreeGrid server library. This library is accessed by php_ffi extension.
To run examples using TreeGrid.dll/so you have to copy file Server/Php/php_ffi.dll on Windows or Server/Php/ffi.so on Linux to PHP extensions directory and should add to your php.ini the directive extension=php_ffi.dll (or ffi.so on Linux). See documentation.
The php_ffi.dll/ffi.so is PHP extension to use DLLs. You can get newest version from PECL (http://pecl.php.net/ffi) and (especially on Linux) compile it from sources by pear install command.

Ajax DLL upon XML file and checking for updates
Main file AjaxServerDLLDisk.html, support code AjaxServerDLLDisk.php
Layout file in Data2Def.xml, data file in Data2.xml.
Demonstrates using server DLL upon static XML data file.
Also demonstrates sharing data among more clients and automatic updating client's data after data on server are modified by another client.
On Windows the PHP engine must be run as ISAPI service and not CGI application, see more information!
The PHP service program must have write access to file /Examples/ServerDLL/Data2.xml !


Main examples - paging

Ajax grids with using server DLL/SO
Main file ../ServerDLL/ServerDLL.html?src=../Php/AjaxServerDLL.php with JavaScript support code ../ServerDLL/ServerDLL.js.
PHP support code AjaxServerDLL.php uses ../../Server/TreeGrid.dll or ../../Server/TreeGrid.so component (TreeGrid server library).
Uses file DataXZDef.xml as layout and DataXY.xml as data source. Where X is example index and Y is rows index (0='S', 1='', 2='E'), Z can be 'E' for server paging.
Remember, XML data files DataXE.xml for 50000 rows are not included in this distribution due their size and can be downloaded from www.treegrid.com/Download/DataE.zip.

To save changes the PHP service program must have write access to /Examples/ServerDLL/tmp directory !

The main file ../ServerDLL/ServerDLL.html can be executed with various parameters: