Composite Primary Key Support *

* An exclusive feature for phpGrid commercial License


In the past, phpGrid supports database SQL that only has a single primary key. If multiple primary keys exist, the recommended workaround was to create an auto-increment column as an alternative single primary key.

Though most cases the above solution is sufficient, as the database grows and its structure evolves, the need to support composite primary key becomes essential, especially in an enterprise environment.

Starting phpGrid 6 (commercial only), you can pass an array of string as primary key in data grid constructor. e.g.

array("KEY1", "KEY2", "KEY3"...);

Lots of resources devoted into developing this important feature while making it simple at the same time. In stead of passing a single string variable in the constructor as the primary key, you can now pass an array of strings as the composite primary key. For a single primary key, you can still use a string or an array with a single string value. e.g.

Complete composite primary key example:

$dg = new C_DataGrid("SELECT * FROM orderdetails", array("productCode", "orderNumber"), "orderdetails");
$dg->enable_edit("FORM", "CRUD");

See Live Example!

For single primary key, you can still pass it as string type, or an array with just a single string element.

$dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders");

– OR –

$dg = new C_DataGrid("SELECT * FROM orders", array("orderNumber"), "orders");

Announcing phpGrid v7.6!