phpGrid Constructor

After successful installation, call the constructor similar to the following:

1
$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=”)

  • 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.

    • $sql_key: The name of the database table primary key. The default is “id”.

      • Starting version 6, phpGrid supports composite primary key (Requires Enterprise or Universal License) 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 statementent.
    • $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 difference 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.
  • 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:
  • Do NOT include WHERE clause in $sql. Instead use set_query_filter method (version 4.2+) to set query filter.
  • If not using the wildcard star(*), the SELECT statement MUST include the primary key as one of the columns.

Single primary key:

1
$dg = new C_DataGrid("SELECT * FROM Orders", "orderNumber", 'Orders');

– OR –

1
$dg = new C_DataGrid("SELECT * FROM Orders", array("orderNumber"), 'Orders');

Composite primary key (Enterprise or Universal license only) new

1
$dg = new C_DataGrid("SELECT * FROM orderdetails", array("productCode", "orderNumber"), "orderdetails");

Check out the composite primary key online example.

No related content found.

Tags: ,