After successful installation, call the constructor similar to the following:
$dg = new C_DataGrid("SELECT * FROM Orders", "orderNumber", "Orders");
The details of phpGrid constructor is explained below:
__constructor($sql, $sql_key=’id’, $sql_table=”, $db_connection=”)
- $sql: SQL SELECT statement. This is the only SQL statement users needs to implement. The SELECT statement must include the primary key as one of the columns if not using the wildcard start(*) in SELECT statement. This parameter can also be a local array (version 5.5+). See phpGrid local array data source usage example.
- $sql_key: The name of the database table primary key. The default is “id”.
- Starting version 6, phpGrid supports composite primary key (Requires commercial licenses) by simply passing an array of string as $sql_key.
- Note that composite PK is not supported as foreign key referential in master/detail and subgrid.
- $sql_table: Name of the database table used in the SQL statement. If not defined, the table name is automatically parsed from the SQL statement.
- $db_connection: Optional. Since version 4.3, the 4th parameter was introduced and used to overwrite connection parameters in conf.php. It allows datagrid to reference to a different data source on the fly. See Reference to Multiple Databases example for more information on this parameter. If you have only one database, you can safely ignore this parameter.
- This is our datagrid object constructor. Use this method to create the phpGrid object. Usually, this is the first line in your code.
Single primary key:
$dg = new C_DataGrid("SELECT * FROM Orders", "orderNumber", 'Orders');
– OR –
$dg = new C_DataGrid("SELECT * FROM Orders", array("orderNumber"), 'Orders');
Composite primary key (commercial licenses only)
$dg = new C_DataGrid("SELECT * FROM orderdetails", array("productCode", "orderNumber"), "orderdetails");
Check out the composite primary key online example.