After successful installation, call the constructor like the following:
1 | $dg = new C_DataGrid("SELECT * FROM Orders", "orderNumber", "Orders"); |
The details of phpGrid constructor are explained below:
__constructor($sql, $sql_key=’id’, $sql_table=”, $db_connection=”)
- Parameter(s):
- $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+). Refer to phpGrid local array data source demo.
- This parameter can also be the name of a stored procedure (version 7.5). In that case, the 2nd parameter is an array containing parameters value.
- $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 fourth 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.
- $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.
- Description:
- This is our datagrid object constructor. Use this method to create the phpGrid object. Usually, this is the first line in your code.
- Example:
X
Single primary key:
1 | $dg = new C_DataGrid("SELECT * FROM Orders", "orderNumber", 'Orders'); |
– OR –
1 |
Composite primary key (commercial licenses only)
1 | $dg = new C_DataGrid("SELECT * FROM orderdetails", array("productCode", "orderNumber"), "orderdetails"); |
Check out the Basic Datagrid example and composite primary key online example.