PDOStatement::getColumnMeta — Returns the metadata of a column in the result set (PHP 5 >= 5.1.0, PECL pdo >= 0.2.0)
array PDOStatement::getColumnMeta ( int $column )
Retrieve metadata for a column indexed starting with 0 in the result set as an associative array.
Note: This function is experimental. The appearance of this function, including its name and its associated documentation, may be modified without notice in future PHP releases. Use this function at your own risk.
Note: Not all PDO drivers support PDOStatement::getColumnMeta().
Column in the column result set whose index starts with 0.
Returns an associative array containing the following values representing metadata for a single column:
name | value |
---|---|
native_type | PHP native type used to represent column values. |
driver:decl_type | The SQL type used to represent column values in the database. If a column in the result set is the result of a function, the value cannot be returned by PDOStatement::getColumnMeta() . |
flags | Any flags set to this column. |
name | Column names returned through the database. |
table | The table name of this column returned through the database |
len | The length of the column. Usually -1 except for floating point decimals |
precision | The numerical precision of this column. Usually 0 except for floating point decimals. |
pdo_type | Column type represented by PDO::PARAM_* constants. |
The following example shows the results of retrieving metadata for a single column using a function (COUNT) in a PDO_SQLITE.
<?php$select = $DB->query('SELECT COUNT(*) FROM fruit');$meta = $select->getColumnMeta(0);var_dump($meta);?>
The above example output:
array(6) { ["native_type"]=> string(7) "integer" ["flags"]=> array(0) { } ["name"]=> string(8) "COUNT(*)" [ "len"]=> int(-1) ["precision"]=> int(0) ["pdo_type"]=> int(2)}