DB::DBAL

The World's Most Powerful Light-Weight DBAL

SetPrimaryKey

setPrimaryKey( string $column_name )

The setPrimaryKey() method allows you to define the primary key for a table. This is extremely helpful when not utilizing caching as it eliminates the need to query the table for it’s primary key.

It is recommended that the setPrimaryKey() method be placed in the table model setup() method:

1
2
3
4
5
6
<?php
class DB_Models_MySQL_MyDatabase_emailsTable extends DB_Inc_Abstracts_Models {
public function setup() {
$this->setPrimaryKey('emailId');
}
}

This will cause the primaryKey to be automatically set before any queries are run on the table. Otherwise, you can use setPrimaryKey() in your query chain:

1
DB::MySQL()->table('emails')->setPrimaryKey('emailId');