uTools-Manuals/docs/php/db2_get_option.html
2019-04-28 19:00:34 +08:00

285 lines
24 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 an option value for a statement resource or a connection resource</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.db2-get-option" class="refentry">
<div class="refnamediv">
<h1 class="refname">db2_get_option</h1>
<p class="verinfo">(PECL ibm_db2 &gt;= 1.6.0)</p><p class="refpurpose"><span class="refname">db2_get_option</span> &mdash; <span class="dc-title">Retrieves an option value for a statement resource or a connection resource</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.db2-get-option-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>db2_get_option</strong></span>
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$resource</code></span>
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$option</code></span>
) : <span class="type">string</span></div>
<p class="para rdfs-comment">
Retrieves the value of a specified option value for a statement resource
or a connection resource.
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.db2-get-option-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">resource</code></dt>
<dd>
<p class="para">
A valid statement resource as returned from
<span class="function"><a href="db2_prepare.html" class="function">db2_prepare()</a></span> or a valid connection resource as
returned from <span class="function"><a href="db2_connect.html" class="function">db2_connect()</a></span> or
<span class="function"><a href="db2_pconnect.html" class="function">db2_pconnect()</a></span>.
</p>
</dd>
<dt>
<code class="parameter">option</code></dt>
<dd>
<p class="para">
A valid statement or connection options. The following new options are available
as of ibm_db2 version 1.6.0. They provide useful tracking information
that can be set during execution with <span class="function"><strong>db2_get_option()</strong></span>.
<blockquote class="note"><p><strong class="note">Note</strong>:
<p class="para">
Prior versions of ibm_db2 do not support these new options.
</p>
<p class="para">
When the value in each option is being set, some servers might not handle
the entire length provided and might truncate the value.
</p>
<p class="para">
To ensure that the data specified in each option is converted correctly
when transmitted to a host system, use only the characters A through Z,
0 through 9, and the underscore (_) or period (.).
</p>
</p></blockquote>
<dl>
<dt>
<code class="parameter">userid</code></dt>
<dd>
<p class="para">
<em>SQL_ATTR_INFO_USERID</em> - A pointer to a null-terminated
character string used to identify the client user ID sent to the host
database server when using DB2 Connect.
<blockquote class="note"><p><strong class="note">Note</strong>:
<p class="para">
DB2 for z/OS and OS/390 servers support up to a length of 16 characters.
This user-id is not to be confused with the authentication user-id, it is for
identification purposes only and is not used for any authorization.
</p>
</p></blockquote>
</p>
</dd>
<dt>
<code class="parameter">acctstr</code></dt>
<dd>
<p class="para">
<em>SQL_ATTR_INFO_ACCTSTR</em> - A pointer to a null-terminated
character string used to identify the client accounting string sent to the
host database server when using DB2 Connect.
<blockquote class="note"><p><strong class="note">Note</strong>:
<p class="para">
DB2 for z/OS and OS/390 servers support up to a length of 200 characters.
</p>
</p></blockquote>
</p>
</dd>
<dt>
<code class="parameter">applname</code></dt>
<dd>
<p class="para">
<em>SQL_ATTR_INFO_APPLNAME</em> - A pointer to a null-terminated
character string used to identify the client application name sent to the
host database server when using DB2 Connect.
<blockquote class="note"><p><strong class="note">Note</strong>:
<p class="para">
DB2 for z/OS and OS/390 servers support up to a length of 32 characters.
</p>
</p></blockquote>
</p>
</dd>
<dt>
<code class="parameter">wrkstnname</code></dt>
<dd>
<p class="para">
<em>SQL_ATTR_INFO_WRKSTNNAME</em> - A pointer to a null-terminated
character string used to identify the client workstation name sent to the
host database server when using DB2 Connect.
<blockquote class="note"><p><strong class="note">Note</strong>:
<p class="para">
DB2 for z/OS and OS/390 servers support up to a length of 18 characters.
</p>
</p></blockquote>
</p>
</dd>
</dl>
</p>
</dd>
</dl>
</p>
<p class="para">
The following table specifies which options are compatible with
the available resource types:
<table class="doctable table">
<caption><strong>Resource-Parameter Matrix</strong></caption>
<col style="text-align: center;" />
<col style="text-align: center;" />
<col style="text-align: center;" />
<col style="text-align: center;" />
<col style="text-align: center;" />
<thead>
<tr>
<th>Key</th>
<th>Value</th>
<th colspan="3">Resource Type</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td class="empty">&nbsp;</td><td class="empty">&nbsp;</td><td>Connection</td>
<td>Statement</td>
<td>Result Set</td>
</tr>
<tr>
<td>userid</td>
<td><em>SQL_ATTR_INFO_USERID</em></td>
<td>X</td>
<td>X</td>
<td>-</td>
</tr>
<tr>
<td>acctstr</td>
<td><em>SQL_ATTR_INFO_ACCTSTR</em></td>
<td>X</td>
<td>X</td>
<td>-</td>
</tr>
<tr>
<td>applname</td>
<td><em>SQL_ATTR_INFO_APPLNAME</em></td>
<td>X</td>
<td>X</td>
<td>-</td>
</tr>
<tr>
<td>wrkstnname</td>
<td><em>SQL_ATTR_INFO_WRKSTNNAME</em></td>
<td>X</td>
<td>X</td>
<td>-</td>
</tr>
</tbody>
</table>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.db2-get-option-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
Returns the current setting of the connection attribute provided on success
或者在失败时返回 <strong><code>FALSE</code></strong>.
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.db2-get-option-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-1262">
<p><strong>Example #1 Setting and retrieving parameters through a connection resource</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Database&nbsp;Connection&nbsp;Parameters&nbsp;*/<br /></span><span style="color: #0000BB">$database&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'SAMPLE'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$user&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$password&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'ibmdb2'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Obtain&nbsp;Connection&nbsp;Resource&nbsp;*/<br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"Client&nbsp;attributes&nbsp;passed&nbsp;through&nbsp;connection&nbsp;string:\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;the&nbsp;associative&nbsp;options&nbsp;array&nbsp;with&nbsp;valid&nbsp;key-value&nbsp;pairs&nbsp;*/<br />/*&nbsp;Assign&nbsp;the&nbsp;attributes&nbsp;through&nbsp;connection&nbsp;string&nbsp;*/<br />/*&nbsp;Access&nbsp;the&nbsp;options&nbsp;specified&nbsp;*/<br /></span><span style="color: #0000BB">$options1&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'userid'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$password</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'userid'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options2&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'acctstr'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'account'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$password</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn2</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'acctstr'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options3&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'applname'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'myapp'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn3&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$password</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options3</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn3</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'applname'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options4&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'wrkstnname'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'workstation'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn4&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$password</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options4</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn4</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'wrkstnname'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br />echo&nbsp;</span><span style="color: #DD0000">"Client&nbsp;attributes&nbsp;passed&nbsp;post-connection:\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;the&nbsp;associative&nbsp;options&nbsp;array&nbsp;with&nbsp;valid&nbsp;key-value&nbsp;pairs&nbsp;*/<br />/*&nbsp;Assign&nbsp;the&nbsp;attributes&nbsp;after&nbsp;a&nbsp;connection&nbsp;is&nbsp;made&nbsp;*/<br />/*&nbsp;Access&nbsp;the&nbsp;options&nbsp;specified&nbsp;*/<br /></span><span style="color: #0000BB">$options5&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'userid'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn5&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$rc&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_set_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn5</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'userid'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options6&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'acctstr'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'account'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn6&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$rc&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_set_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn6</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options6</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn6</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'acctstr'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options7&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'applname'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'myapp'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn7&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$rc&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_set_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn7</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options7</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn7</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'applname'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options8&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'wrkstnname'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'workstation'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn8&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$rc&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_set_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn8</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options8</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn8</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'wrkstnname'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
<div class="example-contents"><p>以上例程会输出:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
Client attributes passed through connection string:
db2inst1
account
myapp
workstation
Client attributes passed post-connection:
db2inst1
account
myapp
workstation</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 seealso" id="refsect1-function.db2-get-option-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="db2_connect.html" class="function" rel="rdfs-seeAlso">db2_connect()</a> - Returns a connection to a database</span></li>
<li class="member"><span class="function"><a href="db2_cursor_type.html" class="function" rel="rdfs-seeAlso">db2_cursor_type()</a> - Returns the cursor type used by a statement resource</span></li>
<li class="member"><span class="function"><a href="db2_exec.html" class="function" rel="rdfs-seeAlso">db2_exec()</a> - Executes an SQL statement directly</span></li>
<li class="member"><span class="function"><a href="db2_set_option.html" class="function" rel="rdfs-seeAlso">db2_set_option()</a> - Set options for connection or statement resources</span></li>
<li class="member"><span class="function"><a href="db2_pconnect.html" class="function" rel="rdfs-seeAlso">db2_pconnect()</a> - Returns a persistent connection to a database</span></li>
<li class="member"><span class="function"><a href="db2_prepare.html" class="function" rel="rdfs-seeAlso">db2_prepare()</a> - Prepares an SQL statement to be executed</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>