Data Sources

Data Sources

Data Sources -- What is a Data Source Driver?

Description

A Data Source is rather self explainitory by it's name alone; however, a Data Source Driver in context to the DataGrid can become a very essential key to your software. A Data Source Driver will interact with your data source directly, such as a DB_DataObject or DB_Result object and handle all of the paging and sorting code for you, resulting in very few lines of code that you will need to write.

How to use the drivers

To use the drivers, you can simply use the bind method, assuming your data source is listed below, otherwise you can use the bindDataSource() method. The bind() method will attempt to detect the datasource type and may not be 100% accurate. Because of this chance for error, you may choose to use the bindDataSource method where you can specifically define the datasource driver to use. This method is also the method of choice if you are building your own custom Data Source Driver.

Currently Available Data Source Drivers

The following listed drivers are currently packaged in with Structures_DataGrid.

PEAR::DB_DataObject Object

The DataObject is the most optimal data source for the datagrid because it allows the datagrid to only fetch the necessary records upon rendering. Please note that when binding to a dataobject, do not run the fetch method prior since the datagrid will run the fetch method during the rendering.

PEAR::DB_Result Object

When using the DB_Result object, please keep in mind that the sorting will not be automatic and must be done in the SQL directly. Also the paging will not be optimized since your entire result set will be limitied. It is best to implement the LIMIT clause manually unless your database platform does not support this.

XML File

XML can simply be presented via the DataGrid. You can bind the Datagrid to a URL directly or via the contents of the XML file.

CSV File

A CSV file can simply be presented via the DataGrid. You can bind the Datagrid to a URL directly or via the contents of the CSV file.

RSS File

An RSS feed can simply be presented via the DataGrid. You can bind the Datagrid to a URL directly or via the contents of the RSS file.

Array

The core data type that the datagrid uses is an Array. The Datagrid maintains it's data in a 2-dimension associative array. The array keys are uses as the column names. This of couse can be changed by specifying the columns directly.

© Copyright 2003-2023 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.