Description
Get primary key of a table using PDO
Function Defination
void function primaryKey($dbTableName);
Parameters Details
| Details | Type | Example |
|---|---|---|
| $dbTableName - table name to be truncated | string | e.g. "emptable" |
Examples
$pdomodel = new PDOModel(); //create object of the PDOModel class
$pdomodel->connect("localhost", "root", "", "pdocrud");//connect to database
/* Get primary key of table function */
$primaryKey = $pdomodel->primaryKey("wp_posts");
More Examples
//Example 1
$primaryKey = $pdomodel->primaryKey("wp_posts");
Result/Output
Return primary key if any else return empty string
Debug
| Option | Details | Example |
|---|---|---|
| $pdomodel->getLastQuery(); | Return last query executed | SHOW INDEXES FROM `wp_posts` WHERE Key_name = 'PRIMARY' |
| print_r($pdomodel->error) | Print errors (if any) |