PDOStatement::getColumnMeta
PDOStatement::getColumnMeta — Returns the metadata of a column in a result set (PHP 5 >= 5.1.0, PECL pdo >= 0.2.0)
Description
Syntax
array PDOStatement::getColumnMeta ( int $column )
Retrieves the metadata for a 0-indexed column in a result set as an associative array.
Note:This function is experimental. The behavior of this function, including its name and its related 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().
Parameters
column
The 0-indexed column in the result set.
Return Values
Returns an associative array containing the following values that represent the metadata of a single column:
| Name | Value |
|---|---|
| native_type | The PHP native type used to represent the column value. |
| driver:decl_type | The SQL type used to represent the column value in the database. If the column in the result set is the result of a function, this value cannot bePDOStatement::getColumnMeta()returned. |
| flags | Any flags set for this column. |
| name | The column name returned by the database. |
| table | The table name for this column returned by the database |
| len | The length of this column. Except for floating-point decimals, it is usually-1 |
| precision | The numeric precision of this column. Except for floating-point decimals, it is usually0 。 |
| pdo_type | withPDO::PARAM_*The column type represented by a constant. |
Examples
Retrieve column metadata
The following example shows the result of retrieving the metadata of a single column generated by a function (COUNT) in PDO_SQLITE.
<?php
$select = $DB->query('SELECT COUNT(*) FROM fruit');
$meta = $select->getColumnMeta(0);
var_dump($meta);
?>
The above example outputs:
array(6) {
["native_type"]=>
string(7) "integer"
["flags"]=>
array(0) {
}
["name"]=>
string(8) "COUNT(*)"
["len"]=>
int(-1)
["precision"]=>
int(0)
["pdo_type"]=>
int(2)
}
Other Extensions
PHP PDO Reference Manual