Db::getColumnNames
Usage
array Db::getColumnNames(string $table_name, [ bool $include_types = false ])Description
Get all column names within a database table, optionally with column type.Parameters
Parameter | Required | Type | Description |
---|---|---|---|
$table_name | Yes | string | The table name to retrieve columns of. |
$include_types | No | bool | Whether or not to also return the column types as well. |
Return Value
If the $include_types parameter is set to false, this will return a one-dimensional array of all common names. Otherwise, it will return an associative array of column names and their types.Examples
Get Column Names
$table = 'admin';
$names = $this->db->getColumnNames($table);
// $names is a one-dimensional array of all column names
// Get names and types
$names = $this->db->getColumnNames($table, true);
// $names is now an associative array of all column names and types