Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PDOStatement::getColumnMeta

PDOStatement::getColumnMeta

PHP PDO Reference ManualPHP PDO Reference Manual

PDOStatement::getColumnMeta — Returns metadata for 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 the result set as an associative array.

**Note:** This function is experimental. The behavior of this function, including its name and related documentation, may be changed in future PHP releases without notice. 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 Value

Returns an associative array containing the following values representing 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 in the database to represent the column value. If the column in the result set is the result of a function, this value cannot be PDOStatement::getColumnMeta() returned.
flags Any flags set on this column.
name The column name returned by the database.
table The table name of this column returned by the database
len The length of the column. Usually, except for floating-point numbers, -1
precision The numeric precision of the column. Usually, except for floating-point numbers, 0 .
pdo_type Starts with PDO::PARAM_* The column type represented by a constant.

Example

Retrieving column metadata

The example below shows, in PDO_SQLITE, the result of retrieving the metadata of a single column generated by a function (COUNT).



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)

}


PHP PDO Reference ManualPHP PDO Reference Manual