📄 function.mysql-field-type.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Get the type of the specified field in a result</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div 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, PECL mysql:1.0)</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 class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><b><b>mysql_field_type</b></b></span> ( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$result</tt></span> , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$field_offset</tt></span> )</div> <p class="para rdfs-comment"> <b>mysql_field_type()</b> is similar to the <a href="function.mysql-field-name.html" class="function">mysql_field_name()</a> function. The arguments are identical, but the field type is returned instead. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt><span class="term"><i><tt class="parameter">result</tt></i></span><dd><p class="para">The result <a href="language.types.resource.html" class="type resource">resource</a> thatis being evaluated. This result comes from a call to <a href="function.mysql-query.html" class="function">mysql_query()</a>.</p></dd></dt> <dt><span class="term"><i><tt class="parameter">field_offset</tt></i></span><dd><p class="para">The numerical field offset. The <i><tt class="parameter">field_offset</tt></i> starts at <i>0</i>. If <i><tt class="parameter">field_offset</tt></i> does not exist, an error of level<b><tt>E_WARNING</tt></b> is also issued.</p></dd></dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The returned field type will be one of <i>"int"</i>, <i>"real"</i>, <i>"string"</i>, <i>"blob"</i>, 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"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 <b>mysql_field_type()</b> example</b></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"><pre><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 binaryint ret 1 not_nullstring dl 128 not_nullstring type 9 not_null enum</pre></div> </pre></div> </div> </p> </div> <div class="refsect1 notes"> <h3 class="title">Notes</h3> <blockquote><p><b class="note">Note</b>: For backward compatibility, the following deprecated alias may be used: <b>mysql_fieldtype()</b> <br /> </p></blockquote> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.mysql-field-name.html" class="function" rel="rdfs-seeAlso">mysql_field_name()</a></li> <li class="member"><a href="function.mysql-field-len.html" class="function" rel="rdfs-seeAlso">mysql_field_len()</a></li> </ul> </p> </div></div><hr /><div 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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -