<!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>Get the type of the specified field in a result</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.mysql-field-table.html">mysql_field_table</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.mysql-free-result.html">mysql_free_result</a></div> <div class="up"><a href="ref.mysql.html">MySQL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.mysql-field-type" class="refentry"> <div class="refnamediv"> <h1 class="refname">mysql_field_type</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">mysql_field_type</span> — <span class="dc-title">Get the type of the specified field in a result</span></p> </div> <div id="function.mysql-field-type-refsynopsisdiv"> <div class="warning"><strong class="warning">Warning</strong> <p class="para">This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the <a href="book.mysqli.html" class="link">MySQLi</a> or <a href="ref.pdo-mysql.html" class="link">PDO_MySQL</a> extension should be used. See also <a href="mysqlinfo.api.choosing.html" class="link">MySQL: choosing an API</a> guide and <a href="faq.databases.html#faq.databases.mysql.deprecated" class="link">related FAQ</a> for more information. Alternatives to this function include:</p> <ul class="simplelist"> <li class="member"> <span class="function"><a href="mysqli-result.fetch-field-direct.html" class="function">mysqli_fetch_field_direct()</a></span> [type]</li> <li class="member"> <span class="methodname"><a href="pdostatement.getcolumnmeta.html" class="methodname">PDOStatement::getColumnMeta()</a></span> [driver:decl_type] or [pdo_type]</li> </ul> </div> </div> <div class="refsect1 description" id="refsect1-function.mysql-field-type-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><strong>mysql_field_type</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$result</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$field_offset</code></span> )</div> <p class="para rdfs-comment"> <span class="function"><strong>mysql_field_type()</strong></span> is similar to the <span class="function"><a href="function.mysql-field-name.html" class="function">mysql_field_name()</a></span> function. The arguments are identical, but the field type is returned instead. </p> </div> <div class="refsect1 parameters" id="refsect1-function.mysql-field-type-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter"> result</code></em></span><dd> <p class="para">The result <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span> that is being evaluated. This result comes from a call to <span class="function"><a href="function.mysql-query.html" class="function">mysql_query()</a></span>.</p></dd> </dt> <dt> <span class="term"><em><code class="parameter"> field_offset</code></em></span><dd> <p class="para">The numerical field offset. The <em><code class="parameter">field_offset</code></em> starts at <em>0</em>. If <em><code class="parameter">field_offset</code></em> does not exist, an error of level <strong><code>E_WARNING</code></strong> is also issued.</p></dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.mysql-field-type-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The returned field type will be one of <em>"int"</em>, <em>"real"</em>, <em>"string"</em>, <em>"blob"</em>, and others as detailed in the <a href="http://dev.mysql.com/doc/" class="link external">» MySQL documentation</a>. </p> </div> <div class="refsect1 examples" id="refsect1-function.mysql-field-type-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-1593"> <p><strong>Example #1 <span class="function"><strong>mysql_field_type()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />mysql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">, </span><span style="color: #DD0000">"mysql_username"</span><span style="color: #007700">, </span><span style="color: #DD0000">"mysql_password"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">mysql_select_db</span><span style="color: #007700">(</span><span style="color: #DD0000">"mysql"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT * FROM func"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$fields </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_num_fields</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$rows </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_num_rows</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$table </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_field_table</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Your '" </span><span style="color: #007700">. </span><span style="color: #0000BB">$table </span><span style="color: #007700">. </span><span style="color: #DD0000">"' table has " </span><span style="color: #007700">. </span><span style="color: #0000BB">$fields </span><span style="color: #007700">. </span><span style="color: #DD0000">" fields and " </span><span style="color: #007700">. </span><span style="color: #0000BB">$rows </span><span style="color: #007700">. </span><span style="color: #DD0000">" record(s)\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">"The table has the following fields:\n"</span><span style="color: #007700">;<br />for (</span><span style="color: #0000BB">$i</span><span style="color: #007700">=</span><span style="color: #0000BB">0</span><span style="color: #007700">; </span><span style="color: #0000BB">$i </span><span style="color: #007700">< </span><span style="color: #0000BB">$fields</span><span style="color: #007700">; </span><span style="color: #0000BB">$i</span><span style="color: #007700">++) {<br /> </span><span style="color: #0000BB">$type </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_field_type</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">, </span><span style="color: #0000BB">$i</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$name </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_field_name</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">, </span><span style="color: #0000BB">$i</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$len </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_field_len</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">, </span><span style="color: #0000BB">$i</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$flags </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_field_flags</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">, </span><span style="color: #0000BB">$i</span><span style="color: #007700">);<br /> echo </span><span style="color: #0000BB">$type </span><span style="color: #007700">. </span><span style="color: #DD0000">" " </span><span style="color: #007700">. </span><span style="color: #0000BB">$name </span><span style="color: #007700">. </span><span style="color: #DD0000">" " </span><span style="color: #007700">. </span><span style="color: #0000BB">$len </span><span style="color: #007700">. </span><span style="color: #DD0000">" " </span><span style="color: #007700">. </span><span style="color: #0000BB">$flags </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">mysql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">mysql_close</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 something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> Your 'func' table has 4 fields and 1 record(s) The table has the following fields: string name 64 not_null primary_key binary int ret 1 not_null string dl 128 not_null string type 9 not_null enum </pre></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-function.mysql-field-type-notes"> <h3 class="title">Notes</h3> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> For backward compatibility, the following deprecated alias may be used: <span class="function"><strong>mysql_fieldtype()</strong></span> </p> </p></blockquote> </div> <div class="refsect1 seealso" id="refsect1-function.mysql-field-type-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.mysql-field-name.html" class="function" rel="rdfs-seeAlso">mysql_field_name()</a> - Get the name of the specified field in a result</span></li> <li class="member"> <span class="function"><a href="function.mysql-field-len.html" class="function" rel="rdfs-seeAlso">mysql_field_len()</a> - Returns the length of the specified field</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.mysql-field-table.html">mysql_field_table</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.mysql-free-result.html">mysql_free_result</a></div> <div class="up"><a href="ref.mysql.html">MySQL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>