📄 function.mssql-fetch-array.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Fetch a result row as an associative array, a numeric array, or both</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.mssql-execute.html">mssql_execute</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.mssql-fetch-assoc.html">mssql_fetch_assoc</a></div> <div class="up"><a href="ref.mssql.html">Mssql Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.mssql-fetch-array" class="refentry"> <div class="refnamediv"> <h1 class="refname">mssql_fetch_array</h1> <p class="verinfo">(PHP 4, PHP 5, PECL odbtp:1.1.1-1.1.4)</p><p class="refpurpose"><span class="refname">mssql_fetch_array</span> — <span class="dc-title">Fetch a result row as an associative array, a numeric array, or both</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>mssql_fetch_array</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">$result_type</tt></span> ] )</div> <p class="para rdfs-comment"> <b>mssql_fetch_array()</b> is an extended version of <a href="function.mssql-fetch-row.html" class="function">mssql_fetch_row()</a>. In addition to storing the data in the numeric indices of the result array, it also stores the data in associative indices, using the field names as keys. </p> <p class="para"> An important thing to note is that using <b>mssql_fetch_array()</b> is NOT significantly slower than using <a href="function.mssql-fetch-row.html" class="function">mssql_fetch_row()</a>, while it provides a significant added value. </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 resource that is being evaluated. This result comes from a call to <a href="function.mssql-query.html" class="function">mssql_query()</a>. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">result_type</tt></i></span> <dd> <p class="para"> The type of array that is to be fetched. It's a constant and can take the following values: <b><tt>MSSQL_ASSOC</tt></b>, <b><tt>MSSQL_NUM</tt></b>, and the default value of <b><tt>MSSQL_BOTH</tt></b>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns an array that corresponds to the fetched row, or <b><tt>FALSE</tt></b> if there are no more rows. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 <b>mssql_fetch_array()</b> example</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// Send a select query to MSSQL<br /></span><span style="color: #0000BB">$query </span><span style="color: #007700">= </span><span style="color: #0000BB">mssql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT [username], [name] FROM [php].[dbo].[userlist]'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Check if there were any records<br /></span><span style="color: #007700">if(!</span><span style="color: #0000BB">mssql_num_rows</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">))<br />{<br /> echo </span><span style="color: #DD0000">'No records found'</span><span style="color: #007700">;<br />}<br />else<br />{<br /> </span><span style="color: #FF8000">// The following is equal to the code below:<br /> //<br /> // while($row = mssql_fetch_row($query))<br /><br /> </span><span style="color: #007700">while(</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">mssql_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">, </span><span style="color: #0000BB">MSSQL_NUM</span><span style="color: #007700">))<br /> {<br /> </span><span style="color: #FF8000">// ...<br /> </span><span style="color: #007700">}<br />}<br /><br /></span><span style="color: #FF8000">// Free the query result<br /></span><span style="color: #0000BB">mssql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 notes"> <h3 class="title">Notes</h3> <blockquote><p><b class="note">Note</b>: <span class="simpara">Field names returned by this functionare <em class="emphasis">case-sensitive</em>.</span></p></blockquote> <blockquote><p><b class="note">Note</b>: <span class="simpara">This function sets NULL fields tothe PHP <b><tt>NULL</tt></b> value.</span></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.mssql-fetch-row.html" class="function" rel="rdfs-seeAlso">mssql_fetch_row()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.mssql-execute.html">mssql_execute</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.mssql-fetch-assoc.html">mssql_fetch_assoc</a></div> <div class="up"><a href="ref.mssql.html">Mssql 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 + -