<!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><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.db2-free-stmt.html">db2_free_stmt</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.db2-last-insert-id.html">db2_last_insert_id</a></div> <div class="up"><a href="ref.ibm-db2.html">IBM DB2 Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.db2-get-option" class="refentry"> <div class="refnamediv"> <h1 class="refname">db2_get_option</h1> <p class="verinfo">(PECL ibm_db2 >= 1.6.0)</p><p class="refpurpose"><span class="refname">db2_get_option</span> — <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">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <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> )</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">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">resource</code></em></span> <dd> <p class="para"> A valid statement resource as returned from <span class="function"><a href="function.db2-prepare.html" class="function">db2_prepare()</a></span> or a valid connection resource as returned from <span class="function"><a href="function.db2-connect.html" class="function">db2_connect()</a></span> or <span class="function"><a href="function.db2-pconnect.html" class="function">db2_pconnect()</a></span>. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">option</code></em></span> <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> <span class="term"><em><code class="parameter">userid</code></em></span> <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> <dt> <span class="term"><em><code class="parameter">acctstr</code></em></span> <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> <dt> <span class="term"><em><code class="parameter">applname</code></em></span> <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> <dt> <span class="term"><em><code class="parameter">wrkstnname</code></em></span> <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> </dt> </dl> </p> </dd> </dt> </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"> </td><td class="empty"> </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">Return Values</h3> <p class="para"> Returns the current setting of the connection attribute provided on success or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 examples" id="refsect1-function.db2-get-option-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-1172"> <p><strong>Example #1 Setting and retrieving parameters through a connection resource</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">/* Database Connection Parameters */<br /></span><span style="color: #0000BB">$database </span><span style="color: #007700">= </span><span style="color: #DD0000">'SAMPLE'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$user </span><span style="color: #007700">= </span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$password </span><span style="color: #007700">= </span><span style="color: #DD0000">'ibmdb2'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/* Obtain Connection Resource */<br /></span><span style="color: #0000BB">$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">"Client attributes passed through connection string:\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/* Create the associative options array with valid key-value pairs */<br />/* Assign the attributes through connection string */<br />/* Access the options specified */<br /></span><span style="color: #0000BB">$options1 </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'userid' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn1 </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$password</span><span style="color: #007700">, </span><span style="color: #0000BB">$options1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$val </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn1</span><span style="color: #007700">, </span><span style="color: #DD0000">'userid'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$val </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options2 </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'acctstr' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'account'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn2 </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$password</span><span style="color: #007700">, </span><span style="color: #0000BB">$options2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$val </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn2</span><span style="color: #007700">, </span><span style="color: #DD0000">'acctstr'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$val </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options3 </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'applname' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'myapp'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn3 </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$password</span><span style="color: #007700">, </span><span style="color: #0000BB">$options3</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$val </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn3</span><span style="color: #007700">, </span><span style="color: #DD0000">'applname'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$val </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options4 </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'wrkstnname' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'workstation'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn4 </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$password</span><span style="color: #007700">, </span><span style="color: #0000BB">$options4</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$val </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn4</span><span style="color: #007700">, </span><span style="color: #DD0000">'wrkstnname'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$val </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br />echo </span><span style="color: #DD0000">"Client attributes passed post-connection:\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/* Create the associative options array with valid key-value pairs */<br />/* Assign the attributes after a connection is made */<br />/* Access the options specified */<br /></span><span style="color: #0000BB">$options5 </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'userid' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn5 </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$rc </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_set_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn5</span><span style="color: #007700">, </span><span style="color: #0000BB">$options5</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$val </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn5</span><span style="color: #007700">, </span><span style="color: #DD0000">'userid'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$val </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options6 </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'acctstr' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'account'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn6 </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$rc </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_set_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn6</span><span style="color: #007700">, </span><span style="color: #0000BB">$options6</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$val </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn6</span><span style="color: #007700">, </span><span style="color: #DD0000">'acctstr'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$val </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options7 </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'applname' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'myapp'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn7 </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$rc </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_set_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn7</span><span style="color: #007700">, </span><span style="color: #0000BB">$options7</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$val </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn7</span><span style="color: #007700">, </span><span style="color: #DD0000">'applname'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$val </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options8 </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'wrkstnname' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'workstation'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn8 </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$rc </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_set_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn8</span><span style="color: #007700">, </span><span style="color: #0000BB">$options8</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$val </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn8</span><span style="color: #007700">, </span><span style="color: #DD0000">'wrkstnname'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$val </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output:</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">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.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="function.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="function.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="function.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="function.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="function.db2-prepare.html" class="function" rel="rdfs-seeAlso">db2_prepare()</a> - Prepares an SQL statement to be executed</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.db2-free-stmt.html">db2_free_stmt</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.db2-last-insert-id.html">db2_last_insert_id</a></div> <div class="up"><a href="ref.ibm-db2.html">IBM DB2 Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>