Composite PK Archives | phpGrid - PHP Datagrid Create PHP grids in minutes, not hours. Fri, 29 Nov 2024 23:49:37 +0000 en-US hourly 1 CodeProjecthttps://wordpress.org/?v=7.0.3 129966043 Composite Primary Key Support * https://phpgrid.com/example/composite-primary-key-support/ Fri, 18 Oct 2013 00:47:10 +0000 http://phpgrid.com/?p=2663 * 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 […]

The post Composite Primary Key Support * appeared first on phpGrid - PHP Datagrid.

]]>
* 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");

The post Composite Primary Key Support * appeared first on phpGrid - PHP Datagrid.

]]>
2663