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.

1
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:

1
2
3
4
5
6
7
// Always include namespace and conf.php on TOP of the script.
use phpCtrl\C_DataGrid;
require_once("/file/path/to/conf.php");  

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

See Live Example!

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

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

– OR –

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