Latest web development tutorials

PDOStatement :: getColumnMeta

PHP PDO Reference Manual PHP PDO Reference Manual

PDOStatement :: getColumnMeta - Returns result set metadata of a (PHP 5> = 5.1.0, PECL pdo> = 0.2.0)


Explanation

grammar

array PDOStatement::getColumnMeta ( int $column )

Retrieving a result set to the zero-indexed metadata columns as an associative array.

Note: This function is experimental. This function of representation, including the name and associated documentation may be modified without notice on future release of PHP. Use this function at your own risk.

Note: Not all PDO drivers support PDOStatement :: getColumnMeta ().


parameter

column
The result set to zero-indexed columns.


return value

It returns an associative array that contains the following values ​​represent a single column of metadata:

Metadata columns
name value
native_type For PHP native type indicates column values.
driver: decl_type SQL in the database used to indicate the type of column values. If the result set column is the result of a function, then the value can not be () Returns PDOStatement :: getColumnMeta.
flags Any settings in this column mark.
name Through the database column names returned.
table Database table name returned by the column
len The length of the column. In addition to the usual decimal floating point -1
precision Numerical precision of the column. In addition to the usual decimal floating point zero.
pdo_type In PDO :: PARAM_ * constants represented by column type.

Examples

Metadata search column

The following example shows a PDO_SQLITE, the retrieval result generates a single column of metadata through a function (COUNT).

<?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)
}

PHP PDO Reference Manual PHP PDO Reference Manual