<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Returns metadata for a column in a result set</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="pdostatement.getattribute.html">PDOStatement::getAttribute</a></div> <div class="next" style="text-align: right; float: right;"><a href="pdostatement.nextrowset.html">PDOStatement::nextRowset</a></div> <div class="up"><a href="class.pdostatement.html">PDOStatement</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="pdostatement.getcolumnmeta" class="refentry"> <div class="refnamediv"> <h1 class="refname">PDOStatement::getColumnMeta</h1> <p class="verinfo">(PHP 5 >= 5.1.0, PECL pdo >= 0.2.0)</p><p class="refpurpose"><span class="refname">PDOStatement::getColumnMeta</span> — <span class="dc-title"> Returns metadata for a column in a result set </span></p> </div> <div class="refsect1 description" id="refsect1-pdostatement.getcolumnmeta-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">array</span> <span class="methodname"><strong>PDOStatement::getColumnMeta</strong></span> ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$column</code></span> )</div> <div class="warning"><strong class="warning">Warning</strong><p class="simpara">This function is <em class="emphasis">EXPERIMENTAL</em>. The behaviour of this function, its name, and surrounding documentation may change without notice in a future release of PHP. This function should be used at your own risk. </p></div> <p class="para"> Retrieves the metadata for a 0-indexed column in a result set as an associative array. </p> <div class="warning"><strong class="warning">Warning</strong> <p class="simpara"> Not all PDO drivers support <span class="function"><strong>PDOStatement::getColumnMeta()</strong></span>. </p> </div> </div> <div class="refsect1 parameters" id="refsect1-pdostatement.getcolumnmeta-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">column</code></em></span> <dd> <p class="para"> The 0-indexed column in the result set. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-pdostatement.getcolumnmeta-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns an associative array containing the following values representing the metadata for a single column: </p> <table class="doctable table"> <caption><strong>Column metadata</strong></caption> <col /> <col /> <thead> <tr> <th>Name</th> <th>Value</th> </tr> </thead> <tbody class="tbody"> <tr> <td><em>native_type</em></td> <td>The PHP native type used to represent the column value.</td> </tr> <tr> <td><em>driver:decl_type</em></td> <td>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 is not returned by <span class="function"><strong>PDOStatement::getColumnMeta()</strong></span>. </td> </tr> <tr> <td><em>flags</em></td> <td>Any flags set for this column.</td> </tr> <tr> <td><em>name</em></td> <td>The name of this column as returned by the database.</td> </tr> <tr> <td><em>table</em></td> <td>The name of this column's table as returned by the database.</td> </tr> <tr> <td><em>len</em></td> <td>The length of this column. Normally <em>-1</em> for types other than floating point decimals.</td> </tr> <tr> <td><em>precision</em></td> <td>The numeric precision of this column. Normally <em>0</em> for types other than floating point decimals.</td> </tr> <tr> <td><em>pdo_type</em></td> <td>The type of this column as represented by the <a href="pdo.constants.html" class="link"><em>PDO::PARAM_*</em> constants</a>.</td> </tr> </tbody> </table> <p class="para"> Returns <strong><code>FALSE</code></strong> if the requested column does not exist in the result set, or if no result set exists. </p> </div> <div class="refsect1 changelog" id="refsect1-pdostatement.getcolumnmeta-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>5.2.3</td> <td><em>table</em> field</td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-pdostatement.getcolumnmeta-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-958"> <p><strong>Example #1 Retrieving column metadata</strong></p> <div class="example-contents"><p> The following example shows the results of retrieving the metadata for a single column generated by a function (COUNT) in a PDO_SQLITE driver. </p></div> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$select </span><span style="color: #007700">= </span><span style="color: #0000BB">$DB</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT COUNT(*) FROM fruit'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$meta </span><span style="color: #007700">= </span><span style="color: #0000BB">$select</span><span style="color: #007700">-></span><span style="color: #0000BB">getColumnMeta</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$meta</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> array(6) { ["native_type"]=> string(7) "integer" ["flags"]=> array(0) { } ["name"]=> string(8) "COUNT(*)" ["len"]=> int(-1) ["precision"]=> int(0) ["pdo_type"]=> int(2) } </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-pdostatement.getcolumnmeta-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="pdostatement.columncount.html" class="function" rel="rdfs-seeAlso">PDOStatement::columnCount()</a> - Returns the number of columns in the result set</span></li> <li class="member"> <span class="function"><a href="pdostatement.rowcount.html" class="function" rel="rdfs-seeAlso">PDOStatement::rowCount()</a> - Returns the number of rows affected by the last SQL statement</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="pdostatement.getattribute.html">PDOStatement::getAttribute</a></div> <div class="next" style="text-align: right; float: right;"><a href="pdostatement.nextrowset.html">PDOStatement::nextRowset</a></div> <div class="up"><a href="class.pdostatement.html">PDOStatement</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>