PHP PDOStatement:: getColumnMeta Explanation

  • 2021-11-14 05:07:58
  • OfStack

PDOStatement::getColumnMeta

PDOStatement:: getColumnMeta-Returns metadata for 1 column in the result set (PHP 5 > = 5.1.0, PECL pdo > = 0.2.0)

Description

Grammar


array PDOStatement::getColumnMeta ( int $column )

Retrieves the metadata of a column indexed starting with 0 in the result set as an associative array.

Note: This function is experimental. The representation of this function, including its name and 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() .

Parameter

column

Columns in the result set that are indexed starting with 0.

Return value

Returns an associative array containing the following values representing metadata for a single column:

Metadata for columns

Name value
native_type is used to represent the PHP native type of the column value.
driver: decl_type the SQL type used in the database to represent column values. If the column in the result set is the result of 1 function, the value cannot be returned by PDOStatement:: getColumnMeta ().
flags Any tag set to this column.
name the column name returned through the database.
table the table name of the column returned through the database
len the length of the column. Normally-1 except for floating-point decimals
precision the numerical accuracy of this column. Usually 0 except floating-point decimals.
pdo_type the column type represented by the PDO:: PARAM_* constant.

Instances

Retrieve metadata for columns

The following example shows the result of retrieving a metadata that generated a single column through a function (COUNT) in an PDO_SQLITE.


<?php
$select = $DB->query('SELECT COUNT(*) FROM fruit');
$meta = $select->getColumnMeta(0);
var_dump($meta);
?>

Output of the above example:


array(6) {
 ["native_type"]=>
 string(7) "integer"
 ["flags"]=>
 array(0) {
 }
 ["name"]=>
 string(8) "COUNT(*)"
 ["len"]=>
 int(-1)
 ["precision"]=>
 int(0)
 ["pdo_type"]=>
 int(2)
}

Summarize


Related articles: