function.sqlite-fetch-column-types.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 195 行
HTML
195 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Return an array of column types from a particular table</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.sqlite-fetch-array.html">sqlite_fetch_array</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.sqlite-fetch-object.html">sqlite_fetch_object</a></div> <div class="up"><a href="ref.sqlite.html">SQLite Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.sqlite-fetch-column-types" class="refentry"> <div class="refnamediv"> <h1 class="refname">sqlite_fetch_column_types</h1> <h1 class="refname">SQLiteDatabase->fetchColumnTypes</h1> <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">sqlite_fetch_column_types</span> -- <span class="refname">SQLiteDatabase->fetchColumnTypes</span> — <span class="dc-title"> Return an array of column types from a particular table </span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">array</span> <span class="methodname"><b><b>sqlite_fetch_column_types</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$table_name</tt></span> , <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$dbhandle</tt></span> [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$result_type</tt></span> ] )</div> <p class="para rdfs-comment">Object oriented style (method):</p> <div class="classsynopsis"> <div class="ooclass"><b class="classname">SQLiteDatabase</b></div> <div class="methodsynopsis dc-description"> <span class="type">array</span> <span class="methodname"><b><b>fetchColumnTypes</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$table_name</tt></span> [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$result_type</tt></span> ] )</div> </div> <p class="para"> <b>sqlite_fetch_column_types()</b> returns an array of column data types from the specified <i><tt class="parameter">table_name</tt></i> table. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">table_name</tt></i></span> <dd> <p class="para"> The table name to query. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">dbhandle</tt></i></span> <dd> <p class="para"> The SQLite Database resource; returned from <a href="function.sqlite-open.html" class="function">sqlite_open()</a> when used procedurally. This parameter is not required when using the object-oriented method. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">result_type</tt></i></span> <dd> <p class="para"> The optional <i><tt class="parameter">result_type</tt></i> parameter accepts a constant and determines how the returned array will be indexed. Using <b><tt>SQLITE_ASSOC</tt></b> will return only associative indices (named fields) while <b><tt>SQLITE_NUM</tt></b> will return only numerical indices (ordinal field numbers). <b><tt>SQLITE_BOTH</tt></b> will return both associative and numerical indices. <b><tt>SQLITE_ASSOC</tt></b> is the default for this function. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns an array of column data types; <b><tt>FALSE</tt></b> on error. </p> <p class="para">The column names returned by<b><tt>SQLITE_ASSOC</tt></b> and <b><tt>SQLITE_BOTH</tt></b> will becase-folded according to the value of the<a href="sqlite.configuration.html#ini.sqlite.assoc-case" class="link">sqlite.assoc_case</a> configurationoption.</p> </div> <div class="refsect1 changelog"> <h3 class="title">ChangeLog</h3> <p class="para"> <table class="informaltable"> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Version</th> <th colspan="1">Description</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">5.1.0</td> <td colspan="1" rowspan="1" align="left">Added <i><tt class="parameter">result_type</tt></i></td> </tr> </tbody> </colgroup> </table> </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 Procedural example</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$db </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlite_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'mysqlitedb'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">sqlite_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">, </span><span style="color: #DD0000">'CREATE TABLE foo (bar varchar(10), arf text)'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$cols </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlite_fetch_column_types</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">, </span><span style="color: #0000BB">$db</span><span style="color: #007700">, </span><span style="color: #0000BB">SQLITE_ASSOC</span><span style="color: #007700">);<br /><br />foreach (</span><span style="color: #0000BB">$cols </span><span style="color: #007700">as </span><span style="color: #0000BB">$column </span><span style="color: #007700">=> </span><span style="color: #0000BB">$type</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"Column: $column Type: $type"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> <p class="para"> <div class="example"> <p><b>Example #2 Object-oriented example</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$db </span><span style="color: #007700">= new </span><span style="color: #0000BB">SQLiteDatabase</span><span style="color: #007700">(</span><span style="color: #DD0000">'mysqlitedb'</span><span style="color: #007700">);<br /></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">'CREATE TABLE foo (bar varchar(10), arf text)'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$cols </span><span style="color: #007700">= </span><span style="color: #0000BB">$db</span><span style="color: #007700">-></span><span style="color: #0000BB">fetchColumnTypes</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">, </span><span style="color: #0000BB">SQLITE_ASSOC</span><span style="color: #007700">);<br /><br />foreach (</span><span style="color: #0000BB">$cols </span><span style="color: #007700">as </span><span style="color: #0000BB">$column </span><span style="color: #007700">=> </span><span style="color: #0000BB">$type</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"Column: $column Type: $type"</span><span style="color: #007700">;<br />}<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"><pre><div class="cdata"><pre>Column: bar Type: VARCHARColumn: arf Type: TEXT</pre></div> </pre></div> </div> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.sqlite-fetch-array.html">sqlite_fetch_array</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.sqlite-fetch-object.html">sqlite_fetch_object</a></div> <div class="up"><a href="ref.sqlite.html">SQLite Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?