mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 05:26:57 +08:00
657 lines
31 KiB
HTML
657 lines
31 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>Returns a persistent connection to a database</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.db2-pconnect" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">db2_pconnect</h1>
|
|
<p class="verinfo">(PECL ibm_db2 >= 1.0.0)</p><p class="refpurpose"><span class="refname">db2_pconnect</span> — <span class="dc-title">
|
|
Returns a persistent connection to a database
|
|
</span></p>
|
|
|
|
</div>
|
|
<div class="refsect1 description" id="refsect1-function.db2-pconnect-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>db2_pconnect</strong></span>
|
|
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$database</code></span>
|
|
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$username</code></span>
|
|
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$password</code></span>
|
|
[, <span class="methodparam"><span class="type">array</span> <code class="parameter">$options</code></span>
|
|
] ) : <span class="type">resource</span></div>
|
|
|
|
|
|
|
|
<p class="para rdfs-comment">
|
|
Returns a persistent connection to an IBM DB2 Universal Database, IBM
|
|
Cloudscape, or Apache Derby database.
|
|
</p>
|
|
|
|
<p class="para">
|
|
For more information on persistent
|
|
connections, refer to <a href="features.persistent_connections.html" class="xref">数据库持久连接</a>.
|
|
</p>
|
|
|
|
<p class="para">
|
|
Calling <span class="function"><a href="db2_close.html" class="function">db2_close()</a></span> on a persistent connection always
|
|
returns <strong><code>TRUE</code></strong>, but the underlying DB2 client connection remains open and
|
|
waiting to serve the next matching <span class="function"><strong>db2_pconnect()</strong></span>
|
|
request.
|
|
</p>
|
|
|
|
<p class="para">
|
|
Users running version 1.9.0 or later of ibm_db2 should be aware that the
|
|
extension will perform a transaction rollback on persistent connections at
|
|
the end of a request, thus ending the transaction. This prevents the
|
|
transaction block from carrying over to the next request which uses that
|
|
connection if script execution ends before the transaction block does.
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.db2-pconnect-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">database</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The database alias in the DB2 client catalog.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">username</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The username with which you are connecting to the database.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">password</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The password with which you are connecting to the database.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">options</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
An associative array of connection options that affect the behavior
|
|
of the connection, where valid array keys include:
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">autocommit</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Passing the <em>DB2_AUTOCOMMIT_ON</em> value turns
|
|
autocommit on for this connection handle.
|
|
</p>
|
|
<p class="para">
|
|
Passing the <em>DB2_AUTOCOMMIT_OFF</em> value turns
|
|
autocommit off for this connection handle.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">DB2_ATTR_CASE</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Passing the <em>DB2_CASE_NATURAL</em> value specifies
|
|
that column names are returned in natural case.
|
|
</p>
|
|
<p class="para">
|
|
Passing the <em>DB2_CASE_LOWER</em> value specifies
|
|
that column names are returned in lower case.
|
|
</p>
|
|
<p class="para">
|
|
Passing the <em>DB2_CASE_UPPER</em> value specifies
|
|
that column names are returned in upper case.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">CURSOR</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Passing the <em>DB2_FORWARD_ONLY</em> value specifies a
|
|
forward-only cursor for a statement resource. This is the default
|
|
cursor type and is supported on all database servers.
|
|
</p>
|
|
<p class="para">
|
|
Passing the <em>DB2_SCROLLABLE</em> value specifies a
|
|
scrollable cursor for a statement resource. This mode enables
|
|
random access to rows in a result set, but currently is supported
|
|
only by IBM DB2 Universal Database.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
<p class="para">
|
|
The following new option is available in ibm_db2 version 1.7.0
|
|
and later.
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">trustedcontext</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Passing the DB2_TRUSTED_CONTEXT_ENABLE value turns trusted context
|
|
on for this connection handle. This parameter cannot be set using
|
|
<span class="function"><a href="db2_set_option.html" class="function">db2_set_option()</a></span>.
|
|
</p>
|
|
<p class="para">
|
|
This key works only if the database is cataloged (even if the
|
|
database is local), or if you specify the full DSN when you create
|
|
the connection.
|
|
</p>
|
|
<p class="para">
|
|
To catalog the database, use following commands:
|
|
</p>
|
|
<p class="para">
|
|
<pre class="literallayout">db2 catalog tcpip node loopback remote <SERVERNAME> server <SERVICENAME>
|
|
db2 catalog database <LOCALDBNAME> as <REMOTEDBNAME> at node loopback
|
|
db2 "update dbm cfg using svcename <SERVICENAME>"
|
|
db2set DB2COMM=TCPIP</pre>
|
|
</p>
|
|
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
<p class="para">
|
|
The following new i5/OS options are available in ibm_db2 version 1.5.1
|
|
and later.
|
|
<div class="tip"><strong class="tip">Tip</strong>
|
|
<p class="para">Conflicting connection attributes used in conjunction with persistent
|
|
connections can produce indeterminate results on i5/OS. Site policies should
|
|
be establish for all applications using each persistent connection user
|
|
profile. The default DB2_AUTOCOMMIT_ON is suggested when using persistent connections.
|
|
</p>
|
|
</div>
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">i5_lib</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
A character value that indicates the default library that will be
|
|
used for resolving unqualified file references. This is not valid
|
|
if the connection is using system naming mode.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">i5_naming</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
<em>DB2_I5_NAMING_ON</em> value turns on DB2 UDB CLI iSeries
|
|
system naming mode. Files are qualified using the slash (/) delimiter.
|
|
Unqualified files are resolved using the library list for the job.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_NAMING_OFF</em> value turns off DB2 UDB CLI default
|
|
naming mode, which is SQL naming. Files are qualified using the period (.)
|
|
delimiter. Unqualified files are resolved using either the default library
|
|
or the current user ID.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">i5_commit</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The <code class="parameter">i5_commit</code> attribute should be set before the
|
|
<span class="function"><strong>db2_pconnect()</strong></span>. If the value is changed after the
|
|
connection has been established, and the connection is to a remote data
|
|
source, the change does not take effect until the next successful
|
|
<span class="function"><strong>db2_pconnect()</strong></span> for the connection handle.
|
|
<blockquote class="note"><p><strong class="note">Note</strong>:
|
|
<p class="para">
|
|
The php.ini setting <code class="parameter">ibm_db2.i5_allow_commit</code>==0
|
|
or <em>DB2_I5_TXN_NO_COMMIT</em> is the default, but may be
|
|
overridden with the <code class="parameter">i5_commit</code> option.
|
|
</p>
|
|
</p></blockquote>
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_TXN_NO_COMMIT</em> - Commitment control is not used.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_TXN_READ_UNCOMMITTED</em> - Dirty reads, nonrepeatable
|
|
reads, and phantoms are possible.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_TXN_READ_COMMITTED</em> - Dirty reads are not possible.
|
|
Nonrepeatable reads, and phantoms are possible.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_TXN_REPEATABLE_READ</em> - Dirty reads and nonrepeatable
|
|
reads are not possible. Phantoms are possible.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_TXN_SERIALIZABLE</em> - Transactions are serializable.
|
|
Dirty reads, non-repeatable reads, and phantoms are not possible
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">i5_query_optimize</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
<em>DB2_FIRST_IO</em> All queries are optimized with the goal of
|
|
returning the first page of output as fast as possible. This goal works well
|
|
when the output is controlled by a user who is most likely to cancel the query
|
|
after viewing the first page of output data. Queries coded with an
|
|
OPTIMIZE FOR nnn ROWS clause honor the goal specified by the clause.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_ALL_IO</em> All queries are optimized with the goal of running
|
|
the entire query to completion in the shortest amount of elapsed time. This is a
|
|
good option when the output of a query is being written to a file or report, or
|
|
the interface is queuing the output data. Queries coded with an OPTIMIZE FOR nnn
|
|
ROWS clause honor the goal specified by the clause. This is the default.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">i5_dbcs_alloc</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
<em>DB2_I5_DBCS_ALLOC_ON</em> value turns on DB2 6X allocation scheme
|
|
for DBCS translation column size growth.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_DBCS_ALLOC_OFF</em> value turns off DB2 6X allocation scheme
|
|
for DBCS translation column size growth.
|
|
<blockquote class="note"><p><strong class="note">Note</strong>:
|
|
<p class="para">
|
|
The php.ini setting <code class="parameter">ibm_db2.i5_dbcs_alloc</code>==0 or
|
|
<em>DB2_I5_DBCS_ALLOC_OFF</em> is the default, but may be overridden
|
|
with the <code class="parameter">i5_dbcs_alloc</code> option.
|
|
</p>
|
|
</p></blockquote>
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">i5_date_fmt</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
<em>DB2_I5_FMT_ISO</em> - The International Organization for Standardization
|
|
(ISO) date format yyyy-mm-dd is used. This is the default.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_FMT_USA</em> - The United States date format mm/dd/yyyy is used.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_FMT_EUR</em> - The European date format dd.mm.yyyy is used.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_FMT_JIS</em> - The Japanese Industrial Standard date format
|
|
yyyy-mm-dd is used.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_FMT_MDY</em> - The date format mm/dd/yyyy is used.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_FMT_DMY</em> - The date format dd/mm/yyyy is used.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_FMT_YMD</em> - The date format yy/mm/dd is used.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_FMT_JUL</em> - The Julian date format yy/ddd is used.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_FMT_JOB</em> - The job default is used.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">i5_date_sep</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
<em>DB2_I5_SEP_SLASH</em> - A slash ( / ) is used as the date separator.
|
|
This is the default.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_SEP_DASH</em> - A dash ( - ) is used as the date separator.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_SEP_PERIOD</em> - A period ( . ) is used as the date
|
|
separator.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_SEP_COMMA</em> - A comma ( , ) is used as the date separator.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_SEP_BLANK</em> - A blank is used as the date separator.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_SEP_JOB</em> - The job default is used
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">i5_time_fmt</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
<em>DB2_I5_FMT_ISO</em> - The International Organization for
|
|
Standardization (ISO) time format hh.mm.ss is used. This is the default.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_FMT_USA</em> - The United States time format
|
|
hh:mmxx is used, where xx is AM or PM.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_FMT_EUR</em> - The European time format hh.mm.ss
|
|
is used.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_FMT_JIS</em> - The Japanese Industrial Standard
|
|
time format hh:mm:ss is used.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_FMT_HMS</em> - The hh:mm:ss format is used.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">i5_time_sep</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
<em>DB2_I5_SEP_COLON</em> - A colon ( : ) is used as the time
|
|
separator. This is the default.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_SEP_PERIOD</em> - A period ( . ) is used as the time
|
|
separator.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_SEP_COMMA</em> - A comma ( , ) is used as the time
|
|
separator.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_SEP_BLANK</em> - A blank is used as the time separator.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_SEP_JOB</em> - The job default is used.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">i5_decimal_sep</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
<em>DB2_I5_SEP_PERIOD</em> - A period ( . ) is used as
|
|
the decimal separator. This is the default.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_SEP_COMMA</em> - A comma ( , ) is used as the
|
|
decimal separator.
|
|
</p>
|
|
<p class="para">
|
|
<em>DB2_I5_SEP_JOB</em> - The job default is used.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
<p class="para">
|
|
The following new i5/OS option is available in ibm_db2 version 1.8.0
|
|
and later.
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">i5_libl</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
A character value that indicates the library list that will be used for
|
|
resolving unqualified file references. Specify the library list
|
|
elements separated by blanks 'i5_libl'=>"MYLIB YOURLIB ANYLIB".
|
|
<blockquote class="note"><p><strong class="note">Note</strong>:
|
|
<p class="para">
|
|
i5_libl calls qsys2/qcmdexc('cmd',cmdlen), which is only available
|
|
in i5/OS V5R4 and later.
|
|
</p>
|
|
</p></blockquote>
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.db2-pconnect-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
Returns a connection handle resource if the connection attempt is
|
|
successful. <span class="function"><strong>db2_pconnect()</strong></span> tries to reuse an existing
|
|
connection resource that exactly matches the
|
|
<code class="parameter">database</code>, <code class="parameter">username</code>, and
|
|
<code class="parameter">password</code> parameters. If the connection attempt fails,
|
|
<span class="function"><strong>db2_pconnect()</strong></span> returns <strong><code>FALSE</code></strong>.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 changelog" id="refsect1-function.db2-pconnect-changelog">
|
|
<h3 class="title">更新日志</h3>
|
|
<p class="para">
|
|
<table class="doctable informaltable">
|
|
|
|
<thead>
|
|
<tr>
|
|
<th>版本</th>
|
|
<th>说明</th>
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody class="tbody">
|
|
<tr>
|
|
<td>ibm_db2 1.9.0</td>
|
|
<td>
|
|
Active transactions within a persistent connection will be rolled back
|
|
at the end of each request.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>ibm_db2 1.8.0</td>
|
|
<td>
|
|
The <code class="parameter">i5_libl</code> option is available for i5/OS
|
|
users.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>ibm_db2 1.7.0</td>
|
|
<td>
|
|
The <code class="parameter">trustedcontext</code> option is available.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>ibm_db2 1.5.1</td>
|
|
<td>
|
|
The <code class="parameter">i5_lib</code>, <code class="parameter">i5_naming</code>,
|
|
<code class="parameter">i5_commit</code>,
|
|
<code class="parameter">i5_query_optimize</code>,
|
|
<code class="parameter">i5_dbcs_alloc</code>,
|
|
<code class="parameter">i5_date_fmt</code>,
|
|
<code class="parameter">i5_date_sep</code>,
|
|
<code class="parameter">i5_time_fmt</code>, <code class="parameter">i5_time_sep</code>
|
|
and <code class="parameter">i5_decimal_sep</code> options are available for
|
|
i5/OS users.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.db2-pconnect-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-1268">
|
|
<p><strong>Example #1 A <span class="function"><strong>db2_pconnect()</strong></span> example</strong></p>
|
|
<div class="example-contents"><p>
|
|
In the following example, the first call to
|
|
<span class="function"><strong>db2_pconnect()</strong></span> returns a new persistent connection
|
|
resource. The second call to <span class="function"><strong>db2_pconnect()</strong></span> returns
|
|
a persistent connection resource that simply reuses the first persistent
|
|
connection resource.
|
|
</p></div>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br />$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: #0000BB">$pconn </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_pconnect</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 />if (</span><span style="color: #0000BB">$pconn</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"Persistent connection succeeded."</span><span style="color: #007700">;<br />}<br />else {<br /> echo </span><span style="color: #DD0000">"Persistent connection failed."</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$pconn2 </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_pconnect</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 />if (</span><span style="color: #0000BB">$pconn</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"Second persistent connection succeeded."</span><span style="color: #007700">;<br />}<br />else {<br /> echo </span><span style="color: #DD0000">"Second persistent connection failed."</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
<div class="example-contents"><p>以上例程会输出:</p></div>
|
|
<div class="example-contents screen">
|
|
<div class="cdata"><pre>
|
|
Persistent connection succeeded.
|
|
Second persistent connection succeeded.
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
<div class="example" id="example-1269">
|
|
<p><strong>Example #2 Using trusted context</strong></p>
|
|
<div class="example-contents"><p>
|
|
The following example shows how to enable trusted context, switch
|
|
users, and get the current user ID.
|
|
</p></div>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br /><br />$database </span><span style="color: #007700">= </span><span style="color: #DD0000">"SAMPLE"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$hostname </span><span style="color: #007700">= </span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$port </span><span style="color: #007700">= </span><span style="color: #0000BB">50000</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$authID </span><span style="color: #007700">= </span><span style="color: #DD0000">"db2inst1"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$auth_pass </span><span style="color: #007700">= </span><span style="color: #DD0000">"ibmdb2"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$tc_user </span><span style="color: #007700">= </span><span style="color: #DD0000">"tcuser"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$tc_pass </span><span style="color: #007700">= </span><span style="color: #DD0000">"tcpassword"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$dsn </span><span style="color: #007700">= </span><span style="color: #DD0000">"DATABASE=</span><span style="color: #0000BB">$database</span><span style="color: #DD0000">;HOSTNAME=</span><span style="color: #0000BB">$hostname</span><span style="color: #DD0000">;PORT=</span><span style="color: #0000BB">$port</span><span style="color: #DD0000">;<br /> PROTOCOL=TCPIP;UID=</span><span style="color: #0000BB">$authID</span><span style="color: #DD0000">;PWD=</span><span style="color: #0000BB">$auth_pass</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$options </span><span style="color: #007700">= array (</span><span style="color: #DD0000">"trustedcontext" </span><span style="color: #007700">=> </span><span style="color: #0000BB">DB2_TRUSTED_CONTEXT_ENABLE</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$tc_conn </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_pconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$dsn</span><span style="color: #007700">, </span><span style="color: #DD0000">""</span><span style="color: #007700">, </span><span style="color: #DD0000">""</span><span style="color: #007700">, </span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br />if(</span><span style="color: #0000BB">$tc_conn</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"Explicit trusted connection succeeded.\n"</span><span style="color: #007700">;<br /><br /> if(</span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$tc_conn</span><span style="color: #007700">, </span><span style="color: #DD0000">"trustedcontext"</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">$userBefore </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$tc_conn</span><span style="color: #007700">, </span><span style="color: #DD0000">"trusted_user"</span><span style="color: #007700">);<br /> <br /> </span><span style="color: #FF8000">//Do some work as user 1.<br /><br /> //Switching to trusted user.<br /> </span><span style="color: #0000BB">$parameters </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"trusted_user" </span><span style="color: #007700">=> </span><span style="color: #0000BB">$tc_user</span><span style="color: #007700">, <br /> </span><span style="color: #DD0000">"trusted_password" </span><span style="color: #007700">=> </span><span style="color: #0000BB">$tcuser_pass</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$res </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_set_option </span><span style="color: #007700">(</span><span style="color: #0000BB">$tc_conn</span><span style="color: #007700">, </span><span style="color: #0000BB">$parameters</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /> </span><span style="color: #0000BB">$userAfter </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$tc_conn</span><span style="color: #007700">, </span><span style="color: #DD0000">"trusted_user"</span><span style="color: #007700">);<br /> </span><span style="color: #FF8000">//Do more work as trusted user.<br /><br /> </span><span style="color: #007700">if(</span><span style="color: #0000BB">$userBefore </span><span style="color: #007700">!= </span><span style="color: #0000BB">$userAfter</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"User has been switched." </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">; <br /> }<br /> }<br /><br /> </span><span style="color: #0000BB">db2_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$tc_conn</span><span style="color: #007700">);<br />}<br />else {<br /> echo </span><span style="color: #DD0000">"Explicit trusted connection failed.\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
<div class="example-contents"><p>以上例程会输出:</p></div>
|
|
<div class="example-contents screen">
|
|
<div class="cdata"><pre>
|
|
Explicit trusted connection succeeded.
|
|
User has been switched.
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.db2-pconnect-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>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
|
|
</div></div></div></body></html> |