Example #1
0
 /**
  * Retrieves the name of the first primary key of a given table
  * @param string $table The table
  * @return string|null The primary key, or null if none exists
  */
 private function getPrimaryKey($table)
 {
     if (empty($table)) {
         throw new \InvalidArgumentException('Invalid table name');
     }
     $sql = "SHOW KEYS FROM `{$table}` WHERE Key_name = 'PRIMARY';";
     $result = $this->db->query($sql)->fetch();
     return $result ? $result['Column_name'] : null;
 }