mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 13:57:03 +08:00
187 lines
11 KiB
HTML
187 lines
11 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<title>Retrieves the next row of data in a result set as an object</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.sqlsrv-fetch-object" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">sqlsrv_fetch_object</h1>
|
|
<p class="verinfo">(No version information available, might only be in Git)</p><p class="refpurpose"><span class="refname">sqlsrv_fetch_object</span> — <span class="dc-title">Retrieves the next row of data in a result set as an object</span></p>
|
|
|
|
</div>
|
|
<div class="refsect1 description" id="refsect1-function.sqlsrv-fetch-object-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>sqlsrv_fetch_object</strong></span>
|
|
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$stmt</code></span>
|
|
[, <span class="methodparam"><span class="type">string</span> <code class="parameter">$className</code></span>
|
|
[, <span class="methodparam"><span class="type">array</span> <code class="parameter">$ctorParams</code></span>
|
|
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$row</code></span>
|
|
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$offset</code></span>
|
|
]]]] ) : <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
Retrieves the next row of data in a result set as an instance of the specified
|
|
class with properties that match the row field names and values that correspond
|
|
to the row field values.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.sqlsrv-fetch-object-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">stmt</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
A statement resource created by <span class="function"><a href="sqlsrv_query.html" class="function">sqlsrv_query()</a></span> or
|
|
<span class="function"><a href="sqlsrv_execute.html" class="function">sqlsrv_execute()</a></span>.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">className</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The name of the class to instantiate. If no class name is specified,
|
|
stdClass is instantiated.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">ctorParams</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Values passed to the constructor of the specified class. If the constructor
|
|
of the specified class takes parameters, the ctorParams array must be
|
|
supplied.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">row</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The row to be accessed. This parameter can only be used if the specified
|
|
statement was prepared with a scrollable cursor. In that case, this parameter
|
|
can take on one of the following values:
|
|
<ul class="simplelist">
|
|
<li class="member">SQLSRV_SCROLL_NEXT</li>
|
|
<li class="member">SQLSRV_SCROLL_PRIOR</li>
|
|
<li class="member">SQLSRV_SCROLL_FIRST</li>
|
|
<li class="member">SQLSRV_SCROLL_LAST</li>
|
|
<li class="member">SQLSRV_SCROLL_ABSOLUTE</li>
|
|
<li class="member">SQLSRV_SCROLL_RELATIVE</li>
|
|
</ul>
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">offset</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Specifies the row to be accessed if the row parameter is set to
|
|
<strong><code>SQLSRV_SCROLL_ABSOLUTE</code></strong> or
|
|
<strong><code>SQLSRV_SCROLL_RELATIVE</code></strong>. Note that the first row in
|
|
a result set has index 0.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.sqlsrv-fetch-object-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
Returns an object on success, <strong><code>NULL</code></strong> if there are no more rows to return,
|
|
and <strong><code>FALSE</code></strong> if an error occurs or if the specified class does not exist.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.sqlsrv-fetch-object-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="sqlite3stmt.getsql.example.expanded">
|
|
<p><strong>Example #1 <span class="function"><strong>sqlsrv_fetch_object()</strong></span> example</strong></p>
|
|
<div class="example-contents"><p>
|
|
The following example demonstrates how to retrieve a row as a stdClass object.
|
|
</p></div>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br />$serverName </span><span style="color: #007700">= </span><span style="color: #DD0000">"serverName\sqlexpress"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$connectionInfo </span><span style="color: #007700">= array( </span><span style="color: #DD0000">"Database"</span><span style="color: #007700">=></span><span style="color: #DD0000">"dbName"</span><span style="color: #007700">, </span><span style="color: #DD0000">"UID"</span><span style="color: #007700">=></span><span style="color: #DD0000">"username"</span><span style="color: #007700">, </span><span style="color: #DD0000">"PWD"</span><span style="color: #007700">=></span><span style="color: #DD0000">"password"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlsrv_connect</span><span style="color: #007700">( </span><span style="color: #0000BB">$serverName</span><span style="color: #007700">, </span><span style="color: #0000BB">$connectionInfo</span><span style="color: #007700">);<br />if( </span><span style="color: #0000BB">$conn </span><span style="color: #007700">=== </span><span style="color: #0000BB">false </span><span style="color: #007700">) {<br /> die( </span><span style="color: #0000BB">print_r</span><span style="color: #007700">( </span><span style="color: #0000BB">sqlsrv_errors</span><span style="color: #007700">(), </span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #0000BB">$sql </span><span style="color: #007700">= </span><span style="color: #DD0000">"SELECT fName, lName FROM Table_1"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlsrv_query</span><span style="color: #007700">( </span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #0000BB">$sql</span><span style="color: #007700">);<br />if( </span><span style="color: #0000BB">$stmt </span><span style="color: #007700">=== </span><span style="color: #0000BB">false </span><span style="color: #007700">) {<br /> die( </span><span style="color: #0000BB">print_r</span><span style="color: #007700">( </span><span style="color: #0000BB">sqlsrv_errors</span><span style="color: #007700">(), </span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #FF8000">// Retrieve each row as an object.<br />// Because no class is specified, each row will be retrieved as a stdClass object.<br />// Property names correspond to field names.<br /></span><span style="color: #007700">while( </span><span style="color: #0000BB">$obj </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlsrv_fetch_object</span><span style="color: #007700">( </span><span style="color: #0000BB">$stmt</span><span style="color: #007700">)) {<br /> echo </span><span style="color: #0000BB">$obj</span><span style="color: #007700">-></span><span style="color: #0000BB">fName</span><span style="color: #007700">.</span><span style="color: #DD0000">", "</span><span style="color: #007700">.</span><span style="color: #0000BB">$obj</span><span style="color: #007700">-></span><span style="color: #0000BB">lName</span><span style="color: #007700">.</span><span style="color: #DD0000">"<br />"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 notes" id="refsect1-function.sqlsrv-fetch-object-notes">
|
|
<h3 class="title">注释</h3>
|
|
<p class="para">
|
|
If a class name is specified with the optional $className parameter and the
|
|
class has properties whose names match the result set field names, the corresponding
|
|
result set values are applied to the properties. If a result set field name
|
|
does not match a class property, a property with the result set field name is added
|
|
to the object and the result set value is applied to the property. The following
|
|
rules apply when using the $className parameter:
|
|
<ul class="simplelist">
|
|
<li class="member">Field-property name matching is case-sensitive.</li>
|
|
<li class="member">Field-property matching occurs regardless of access modifiers.</li>
|
|
<li class="member">Class property data types are ignored when applying a field value to a property.</li>
|
|
<li class="member">If the class does not exist, the function returns <strong><code>FALSE</code></strong> and adds an error to the error collection.</li>
|
|
</ul>
|
|
Regardless of whether the $className parameter is supplied, if a field with no
|
|
name is returned, the field value will be ignored and a warning will be added
|
|
to the error collection.
|
|
</p>
|
|
<p class="para">
|
|
When consuming a result set that has multiple columns with the same name, it may
|
|
be better to use <span class="function"><a href="sqlsrv_fetch_array.html" class="function">sqlsrv_fetch_array()</a></span> or the combination of
|
|
<span class="function"><a href="sqlsrv_fetch.html" class="function">sqlsrv_fetch()</a></span> and <span class="function"><a href="sqlsrv_get_field.html" class="function">sqlsrv_get_field()</a></span>.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.sqlsrv-fetch-object-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="sqlsrv_fetch.html" class="function" rel="rdfs-seeAlso">sqlsrv_fetch()</a> - Makes the next row in a result set available for reading</span></li>
|
|
<li class="member"><span class="function"><a href="sqlsrv_fetch_array.html" class="function" rel="rdfs-seeAlso">sqlsrv_fetch_array()</a> - Returns a row as an array</span></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
</div></div></div></body></html> |