<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.mysql.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.mysql-field-type.php',
    1 => 'mysql_field_type',
    2 => '取得结果集中指定字段的类型',
  ),
  'up' => 
  array (
    0 => 'ref.mysql.php',
    1 => 'MySQL 函数',
  ),
  'prev' => 
  array (
    0 => 'function.mysql-field-table.php',
    1 => 'mysql_field_table',
  ),
  'next' => 
  array (
    0 => 'function.mysql-free-result.php',
    1 => 'mysql_free_result',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/mysql/functions/mysql-field-type.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<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> &mdash; <span class="dc-title">
     取得结果集中指定字段的类型
    </span></p>

 </div>

 <div id="function.mysql-field-type-refsynopsisdiv">
  <div class="warning"><strong class="warning">警告</strong>
   <p class="para">本扩展自 PHP 5.5.0
起已废弃，并在自 PHP 7.0.0 开始被移除。应使用 <a href="book.mysqli.php" class="link">MySQLi</a>
或 <a href="ref.pdo-mysql.php" class="link">PDO_MySQL</a> 扩展来替换之。参见 <a href="mysqlinfo.api.choosing.php" class="link">MySQL：选择 API</a> 
指南来获取更多信息。用以替代本函数的有：</p>
   <ul class="simplelist">
    <li><span class="function"><a href="mysqli-result.fetch-field-direct.php" class="function">mysqli_fetch_field_direct()</a></span> [type]</li>
    <li><span class="methodname"><a href="pdostatement.getcolumnmeta.php" 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">说明</h3>
     <div class="methodsynopsis dc-description">
      <span class="methodname"><strong>mysql_field_type</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> <code class="parameter">$result</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$field_offset</code></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

    <p class="para rdfs-comment">
     <span class="function"><strong>mysql_field_type()</strong></span> 和
     <span class="function"><a href="function.mysql-field-name.php" class="function">mysql_field_name()</a></span>
     函数相似。参数完全相同，但返回的是字段类型而不是字段名。字段类型有“int”，“real”，“string”，“blob”以及其它，详见
     <a href="http://dev.mysql.com/doc/" class="link external">&raquo;&nbsp;MySQL 手册</a>。
     <div class="example" id="example-1">
      <p><strong>示例 #1 <span class="function"><strong>mysql_field_type()</strong></span> 例子</strong></p>
      <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?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">&lt; </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">?&gt;</span></span></code></div>
      </div>

      <div class="example-contents"><p>
       以上例子将产生如下输出：
      </p></div>
      <div class="example-contents screen">
<div class="descriptioncode"><pre class="descriptioncode">Your &#039;func&#039; 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>
    <p class="simpara">
     为向下兼容仍然可以使用
     <span class="function"><strong>mysql_fieldtype()</strong></span>，但反对这样做。
    </p>
   </div>


 <div class="refsect1 parameters" id="refsect1-function.mysql-field-type-parameters">
  <h3 class="title">参数</h3>
  <dl>
   <dt>
<code class="parameter">result</code></dt><dd><p class="para"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>
型的结果集。此结果集来自对 <span class="function"><a href="function.mysql-query.php" class="function">mysql_query()</a></span>
的调用。</p></dd>
   <dt>
<code class="parameter">field_offset</code></dt><dd><p class="para">数值型字段偏移量。
<code class="parameter">field_offset</code> 从 <code class="literal">0</code> 开始。如果
<code class="parameter">field_offset</code> 不存在，则会发出一个
<strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> 级别的错误</p></dd>
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mysql-field-type-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="simpara">
   The returned field type
   will be one of <code class="literal">&quot;int&quot;</code>, <code class="literal">&quot;real&quot;</code>,
   <code class="literal">&quot;string&quot;</code>, <code class="literal">&quot;blob&quot;</code>, and others as
   detailed in the <a href="http://dev.mysql.com/doc/" class="link external">&raquo;&nbsp;MySQL
   documentation</a>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mysql-field-type-examples">
  <h3 class="title">示例</h3>
  <div class="example" id="example-2">
   <p><strong>示例 #2 <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">&lt;?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">&lt; </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">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>以上示例的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Your &#039;func&#039; 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>
 </div>


 <div class="refsect1 notes" id="refsect1-function.mysql-field-type-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <span class="simpara">
    为了向下兼容，可以使用下列已废弃的别名：
    <span class="function"><strong>mysql_fieldtype()</strong></span>
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mysql-field-type-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.mysql-field-name.php" class="function" rel="rdfs-seeAlso">mysql_field_name()</a> - 取得结果中指定字段的字段名</span></li>
   <li><span class="function"><a href="function.mysql-field-len.php" class="function" rel="rdfs-seeAlso">mysql_field_len()</a> - 返回指定字段的长度</span></li>
  </ul>
 </div>

  </div><?php manual_footer($setup); ?>