<!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 result set metadata from a prepared statement</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.maxdb-stmt-reset.html">maxdb_stmt_reset</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.maxdb-stmt-send-long-data.html">maxdb_stmt_send_long_data</a></div> <div class="up"><a href="ref.maxdb.html">MaxDB Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.maxdb-stmt-result-metadata" class="refentry"> <div class="refnamediv"> <h1 class="refname">maxdb_stmt_result_metadata</h1> <h1 class="refname">maxdb_stmt::result_metadata</h1> <p class="verinfo">(PECL maxdb >= 1.0)</p><p class="refpurpose"><span class="refname">maxdb_stmt_result_metadata</span> -- <span class="refname">maxdb_stmt::result_metadata</span> — <span class="dc-title">Returns result set metadata from a prepared statement</span></p> </div> <div class="refsect1 description" id="refsect1-function.maxdb-stmt-result-metadata-description"> <h3 class="title">Description</h3> <p class="para">Procedural style</p> <div class="methodsynopsis dc-description"> <span class="type">resource</span> <span class="methodname"><strong>maxdb_stmt_result_metadata</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$stmt</code></span> )</div> <p class="para rdfs-comment">Object oriented style</p> <div class="methodsynopsis dc-description"> <span class="type">resource</span> <span class="methodname"><strong>maxdb_stmt::result_metadata</strong></span> ( <span class="methodparam">void</span> )</div> <p class="para rdfs-comment"> If a statement passed to <span class="function"><a href="function.maxdb-prepare.html" class="function">maxdb_prepare()</a></span> is one that produces a result set, <span class="function"><strong>maxdb_stmt_result_metadata()</strong></span> returns the result resource that can be used to process the meta information such as total number of fields and individual field information. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">This result set pointer can be passed as an argument to any of the field-based functions that process result set metadata, such as: <ul class="itemizedlist"> <li class="listitem"><p class="para"> <span class="function"><a href="function.maxdb-num-fields.html" class="function">maxdb_num_fields()</a></span></p></li> <li class="listitem"><p class="para"> <span class="function"><a href="function.maxdb-fetch-field.html" class="function">maxdb_fetch_field()</a></span></p></li> <li class="listitem"><p class="para"> <span class="function"><a href="function.maxdb-fetch-field-direct.html" class="function">maxdb_fetch_field_direct()</a></span></p></li> <li class="listitem"><p class="para"> <span class="function"><a href="function.maxdb-fetch-fields.html" class="function">maxdb_fetch_fields()</a></span></p></li> <li class="listitem"><p class="para"> <span class="function"><a href="function.maxdb-field-count.html" class="function">maxdb_field_count()</a></span></p></li> <li class="listitem"><p class="para"> <span class="function"><a href="function.maxdb-field-seek.html" class="function">maxdb_field_seek()</a></span></p></li> <li class="listitem"><p class="para"> <span class="function"><a href="function.maxdb-field-tell.html" class="function">maxdb_field_tell()</a></span></p></li> <li class="listitem"><p class="para"> <span class="function"><a href="function.maxdb-free-result.html" class="function">maxdb_free_result()</a></span></p></li> </ul> </p> </p></blockquote> <p class="para"> The result set structure should be freed when you are done with it, which you can do by passing it to <span class="function"><a href="function.maxdb-free-result.html" class="function">maxdb_free_result()</a></span> </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> The result set returned by <span class="function"><strong>maxdb_stmt_result_metadata()</strong></span> contains only metadata. It does not contain any row results. The rows are obtained by using the statement handle with <span class="function"><a href="function.maxdb-fetch.html" class="function">maxdb_fetch()</a></span>. </p> </p></blockquote> </div> <div class="refsect1 returnvalues" id="refsect1-function.maxdb-stmt-result-metadata-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> <span class="function"><strong>maxdb_stmt_result_metadata()</strong></span> returns a result resource or <strong><code>FALSE</code></strong> if an error occurred. </p> </div> <div class="refsect1 examples" id="refsect1-function.maxdb-stmt-result-metadata-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-1341"> <p><strong>Example #1 Object oriented style</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$maxdb </span><span style="color: #007700">= new </span><span style="color: #0000BB">maxdb</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">, </span><span style="color: #DD0000">"MONA"</span><span style="color: #007700">, </span><span style="color: #DD0000">"RED"</span><span style="color: #007700">, </span><span style="color: #DD0000">"DEMODB"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$maxdb</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"CREATE TABLE temp.friends (id int, name varchar(20))"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$maxdb</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT INTO temp.friends VALUES (1,'Hartmut')"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$maxdb</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT INTO temp.friends VALUES (2, 'Ulf')"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">$maxdb</span><span style="color: #007700">-></span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT id, name FROM temp.friends"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-></span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/* get resultset for metadata */<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-></span><span style="color: #0000BB">result_metadata</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/* retrieve field information from metadata result set */<br /></span><span style="color: #0000BB">$field </span><span style="color: #007700">= </span><span style="color: #0000BB">$result</span><span style="color: #007700">-></span><span style="color: #0000BB">fetch_field</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"Fieldname: %s\n"</span><span style="color: #007700">, </span><span style="color: #0000BB">$field</span><span style="color: #007700">-></span><span style="color: #0000BB">name</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* close resultset */<br /></span><span style="color: #0000BB">$result</span><span style="color: #007700">-></span><span style="color: #0000BB">close</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/* close connection */<br /></span><span style="color: #0000BB">$maxdb</span><span style="color: #007700">-></span><span style="color: #0000BB">close</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> <div class="example" id="example-1342"> <p><strong>Example #2 Procedural style</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$link </span><span style="color: #007700">= </span><span style="color: #0000BB">maxdb_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">, </span><span style="color: #DD0000">"MONA"</span><span style="color: #007700">, </span><span style="color: #DD0000">"RED"</span><span style="color: #007700">, </span><span style="color: #DD0000">"DEMODB"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">maxdb_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">, </span><span style="color: #DD0000">"CREATE TABLE temp.friends (id int, name varchar(20))"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">maxdb_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">, </span><span style="color: #DD0000">"INSERT INTO temp.friends VALUES (1,'Hartmut')"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">maxdb_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">, </span><span style="color: #DD0000">"INSERT INTO temp.friends VALUES (2, 'Ulf')"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">maxdb_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">, </span><span style="color: #DD0000">"SELECT id, name FROM temp.friends"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">maxdb_stmt_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* get resultset for metadata */<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">maxdb_stmt_result_metadata</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* retrieve field information from metadata result set */<br /></span><span style="color: #0000BB">$field </span><span style="color: #007700">= </span><span style="color: #0000BB">maxdb_fetch_field</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"Fieldname: %s\n"</span><span style="color: #007700">, </span><span style="color: #0000BB">$field</span><span style="color: #007700">-></span><span style="color: #0000BB">name</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* close resultset */<br /></span><span style="color: #0000BB">maxdb_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* close connection */<br /></span><span style="color: #0000BB">maxdb_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> <p class="para">The above example will output something similar to:</p> <div class="example-contents screen"> <div class="cdata"><pre> Fieldname: ID </pre></div> </div> </div> <div class="refsect1 seealso" id="refsect1-function.maxdb-stmt-result-metadata-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.maxdb-prepare.html" class="function" rel="rdfs-seeAlso">maxdb_prepare()</a> - Prepare an SQL statement for execution</span></li> <li class="member"> <span class="function"><a href="function.maxdb-free-result.html" class="function" rel="rdfs-seeAlso">maxdb_free_result()</a> - Frees the memory associated with a result</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="function.maxdb-stmt-reset.html">maxdb_stmt_reset</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.maxdb-stmt-send-long-data.html">maxdb_stmt_send_long_data</a></div> <div class="up"><a href="ref.maxdb.html">MaxDB Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>