PMA\libraries\Index::getPrimary PHP Method

getPrimary() public static method

return primary if set, false otherwise
public static getPrimary ( string $table, string $schema ) : mixed
$table string table
$schema string schema
return mixed primary index or false if no one exists
    public static function getPrimary($table, $schema)
    {
        Index::_loadIndexes($table, $schema);
        if (isset(Index::$_registry[$schema][$table]['PRIMARY'])) {
            return Index::$_registry[$schema][$table]['PRIMARY'];
        } else {
            return false;
        }
    }

Usage Example

 /**
  * Send table columns for foreign table dropdown
  *
  * @return void
  *
  */
 public function getDropdownValueForTableAction()
 {
     $foreignTable = $_REQUEST['foreignTable'];
     $table_obj = $this->dbi->getTable($_REQUEST['foreignDb'], $foreignTable);
     // Since views do not have keys defined on them provide the full list of
     // columns
     if ($table_obj->isView()) {
         $columnList = $table_obj->getColumns(false, false);
     } else {
         $columnList = $table_obj->getIndexedColumns(false, false);
     }
     $columns = array();
     foreach ($columnList as $column) {
         $columns[] = htmlspecialchars($column);
     }
     $this->response->addJSON('columns', $columns);
     // @todo should be: $server->db($db)->table($table)->primary()
     $primary = Index::getPrimary($foreignTable, $_REQUEST['foreignDb']);
     if (false === $primary) {
         return;
     }
     $this->response->addJSON('primary', array_keys($primary->getColumns()));
 }
All Usage Examples Of PMA\libraries\Index::getPrimary