public getColumns ( string $database, string $table, string $column = null, boolean $full = false, mixed $link = null ) : array | ||
$database | string | name of database |
$table | string | name of table to retrieve columns from |
$column | string | name of column, null to show all columns |
$full | boolean | whether to return full info or only column names |
$link | mixed | mysql link resource |
return | array | array indexed by column names or, if $column is given, flat array description |
public function getColumns($database, $table, $column = null, $full = false, $link = null)
{
$sql = $this->getColumnsSql($database, $table, $column, $full);
$fields = $this->fetchResult($sql, 'Field', null, $link);
if (!is_array($fields) || count($fields) == 0) {
return array();
}
// Check if column is a part of multiple-column index and set its 'Key'.
$indexes = Index::getFromTable($table, $database);
foreach ($fields as $field => $field_data) {
if (!empty($field_data['Key'])) {
continue;
}
foreach ($indexes as $index) {
/** @var Index $index */
if (!$index->hasColumn($field)) {
continue;
}
$index_columns = $index->getColumns();
if ($index_columns[$field]->getSeqInIndex() > 1) {
if ($index->isUnique()) {
$fields[$field]['Key'] = 'UNI';
} else {
$fields[$field]['Key'] = 'MUL';
}
}
}
}
return $column != null ? array_shift($fields) : $fields;
}