downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/function.mssql-fetch-array.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/ref.mssql.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'function.mssql-fetch-array.php',
   
1 => 'mssql_fetch_array',
  ),
 
'up' =>
  array (
   
0 => 'ref.mssql.php',
   
1 => 'Mssql Functions',
  ),
 
'prev' =>
  array (
   
0 => 'function.mssql-execute.php',
   
1 => 'mssql_execute',
  ),
 
'next' =>
  array (
   
0 => 'function.mssql-fetch-assoc.php',
   
1 => 'mssql_fetch_assoc',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<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 &gt;= 1.1.1)</p><p class="refpurpose"><span class="refname">mssql_fetch_array</span> &mdash; <span class="dc-title">Fetch a result row as an associative array, a numeric array, or both</span></p>

 </div>
 
 <a name="function.mssql-fetch-array.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">array</span> <span class="methodname"><b>mssql_fetch_array</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 class="initializer"> = MSSQL_BOTH</span></span>
  ] )</div>

  <p class="para rdfs-comment">
   <b>mssql_fetch_array()</b> is an extended version of
   <a href="function.mssql-fetch-row.php" 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.php" class="function">mssql_fetch_row()</a>, while it
   provides a significant added value.
  </p>
 </div>


 <a name="function.mssql-fetch-array.parameters"></a><div class="refsect1 parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   </p><dl>

    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">result</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       The result resource that is being evaluated. This result comes from a
       call to <a href="function.mssql-query.php" class="function">mssql_query()</a>.
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">result_type</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       The type of array that is to be fetched. It&#039;s a constant and can take
       the following values: <b><tt class="constant">MSSQL_ASSOC</tt></b>,
       <b><tt class="constant">MSSQL_NUM</tt></b>, and the default value of
       <b><tt class="constant">MSSQL_BOTH</tt></b>.
      </p>
     </dd>

   
   </dl>
<p>
  </p>
 </div>


 <a name="function.mssql-fetch-array.returnvalues"></a><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 class="constant">FALSE</tt></b> if there
   are no more rows.
  </p>
 </div>


 <a name="function.mssql-fetch-array.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 <b>mssql_fetch_array()</b> example</b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Send&nbsp;a&nbsp;select&nbsp;query&nbsp;to&nbsp;MSSQL<br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mssql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT&nbsp;[username],&nbsp;[name]&nbsp;FROM&nbsp;[php].[dbo].[userlist]'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Check&nbsp;if&nbsp;there&nbsp;were&nbsp;any&nbsp;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 />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'No&nbsp;records&nbsp;found'</span><span style="color: #007700">;<br />}<br />else<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;The&nbsp;following&nbsp;is&nbsp;equal&nbsp;to&nbsp;the&nbsp;code&nbsp;below:<br />&nbsp;&nbsp;&nbsp;&nbsp;//<br />&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;while($row&nbsp;=&nbsp;mssql_fetch_row($query))<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">while(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mssql_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">MSSQL_NUM</span><span style="color: #007700">))<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;...<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Free&nbsp;the&nbsp;query&nbsp;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">?&gt;</span>
</span>
</code></div>
    </div>

   </div><p>
  </p>
 </div>


 <a name="function.mssql-fetch-array.notes"></a><div class="refsect1 notes">
  <h3 class="title">Notes</h3>
  <blockquote><p><b class="note">Note</b>: <span class="simpara">Field names returned by this function
are <em class="emphasis">case-sensitive</em>.</span></p></blockquote>
  <blockquote><p><b class="note">Note</b>: <span class="simpara">This function sets NULL fields to
the PHP <b><tt class="constant">NULL</tt></b> value.</span></p></blockquote>
 </div>


 <a name="function.mssql-fetch-array.seealso"></a><div class="refsect1 seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   </p><ul class="simplelist">
    <li class="member"><a href="function.mssql-fetch-row.php" class="function" rel="rdfs-seeAlso">mssql_fetch_row()</a> - Get row as enumerated array</li>
   </ul><p>
  </p>
 </div>


</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites