mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 05:26:57 +08:00
125 lines
9.8 KiB
HTML
125 lines
9.8 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>Gets field data from the currently selected row</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.sqlsrv-get-field" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">sqlsrv_get_field</h1>
|
|
<p class="verinfo">(No version information available, might only be in Git)</p><p class="refpurpose"><span class="refname">sqlsrv_get_field</span> — <span class="dc-title">Gets field data from the currently selected row</span></p>
|
|
|
|
</div>
|
|
<div class="refsect1 description" id="refsect1-function.sqlsrv-get-field-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>sqlsrv_get_field</strong></span>
|
|
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$stmt</code></span>
|
|
, <span class="methodparam"><span class="type">int</span> <code class="parameter">$fieldIndex</code></span>
|
|
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$getAsType</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">
|
|
Gets field data from the currently selected row. Fields must be accessed in
|
|
order. Field indices start at 0.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.sqlsrv-get-field-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">stmt</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
A statement resource returned 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">fieldIndex</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The index of the field to be retrieved. Field indices start at 0. Fields
|
|
must be accessed in order. i.e. If you access field index 1, then field
|
|
index 0 will not be available.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">getAsType</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The PHP data type for the returned field data. If this parameter is not
|
|
set, the field data will be returned as its default PHP data type.
|
|
For information about default PHP data types, see
|
|
<a href="http://msdn.microsoft.com/en-us/library/cc296193.aspx" class="link external">» Default PHP Data Types</a>
|
|
in the Microsoft SQLSRV documentation.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.sqlsrv-get-field-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
Returns data from the specified field on success. Returns <strong><code>FALSE</code></strong> otherwise.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.sqlsrv-get-field-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-2582">
|
|
<p><strong>Example #1 <span class="function"><strong>sqlsrv_get_field()</strong></span> example</strong></p>
|
|
<div class="example-contents"><p>
|
|
The following example demonstrates how to retrieve a row with
|
|
<span class="function"><a href="sqlsrv_fetch.html" class="function">sqlsrv_fetch()</a></span> and get the row fields with
|
|
<span class="function"><strong>sqlsrv_get_field()</strong></span>.
|
|
</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 Name, Comment <br /> FROM Table_1<br /> WHERE ReviewID=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">// Make the first (and in this case, only) row of the result set available for reading.<br /></span><span style="color: #007700">if( </span><span style="color: #0000BB">sqlsrv_fetch</span><span style="color: #007700">( </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">// Get the row fields. Field indeces start at 0 and must be retrieved in order.<br />// Retrieving row fields by name is not supported by sqlsrv_get_field.<br /></span><span style="color: #0000BB">$name </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlsrv_get_field</span><span style="color: #007700">( </span><span style="color: #0000BB">$stmt</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$name</span><span style="color: #DD0000">: "</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$comment </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlsrv_get_field</span><span style="color: #007700">( </span><span style="color: #0000BB">$stmt</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$comment</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.sqlsrv-get-field-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>
|
|
<li class="member"><span class="function"><a href="sqlsrv_fetch_object.html" class="function" rel="rdfs-seeAlso">sqlsrv_fetch_object()</a> - Retrieves the next row of data in a result set as an object</span></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
</div></div></div></body></html> |