mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 05:26:57 +08:00
119 lines
7.8 KiB
HTML
119 lines
7.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>Returns the auto generated ID of the last insert query that successfully
|
|
executed on this connection</title>
|
|
</head>
|
|
<body class="docs"></div>
|
|
<div id="layout">
|
|
<div id="layout-content"><div id="function.db2-last-insert-id" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">db2_last_insert_id</h1>
|
|
<p class="verinfo">(PECL ibm_db2 >= 1.7.1)</p><p class="refpurpose"><span class="refname">db2_last_insert_id</span> — <span class="dc-title">Returns the auto generated ID of the last insert query that successfully
|
|
executed on this connection</span></p>
|
|
|
|
</div>
|
|
|
|
<div class="refsect1 description" id="refsect1-function.db2-last-insert-id-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>db2_last_insert_id</strong></span>
|
|
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$resource</code></span>
|
|
) : <span class="type">string</span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
Returns the auto generated ID of the last insert query that successfully
|
|
executed on this connection.
|
|
</p>
|
|
<p class="para">
|
|
The result of this function is not affected by any of the following:
|
|
<ul class="itemizedlist">
|
|
<li class="listitem">
|
|
<p class="para">
|
|
A single row INSERT statement with a VALUES clause for a table without an identity column.
|
|
</p>
|
|
</li>
|
|
<li class="listitem">
|
|
<p class="para">
|
|
A multiple row INSERT statement with a VALUES clause.
|
|
</p>
|
|
</li>
|
|
<li class="listitem">
|
|
<p class="para">
|
|
An INSERT statement with a fullselect.
|
|
</p>
|
|
</li>
|
|
<li class="listitem">
|
|
<p class="para">
|
|
A ROLLBACK TO SAVEPOINT statement.
|
|
</p>
|
|
</li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.db2-last-insert-id-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">resource</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
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>. The value of this parameter cannot be a
|
|
statement resource or result set resource.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.db2-last-insert-id-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
Returns the auto generated ID of last insert query that successfully
|
|
executed on this connection.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.db2-last-insert-id-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-1263">
|
|
<p><strong>Example #1 A <span class="function"><strong>db2_last_insert_id()</strong></span> example</strong></p>
|
|
<div class="example-contents"><p>
|
|
The following example shows how to return the
|
|
auto generated ID of last insert query that successfully
|
|
executed on this connection.
|
|
</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">$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">$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 />if(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$createTable </span><span style="color: #007700">= </span><span style="color: #DD0000">"CREATE TABLE lastInsertID <br /> (id integer GENERATED BY DEFAULT AS IDENTITY, name varchar(20))"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$insertTable </span><span style="color: #007700">= </span><span style="color: #DD0000">"INSERT INTO lastInsertID (name) VALUES ('Temp Name')"</span><span style="color: #007700">;<br /><br /> </span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= @</span><span style="color: #0000BB">db2_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #0000BB">$createTable</span><span style="color: #007700">);<br /><br /> </span><span style="color: #FF8000">/* Checking for single row inserted. */<br /> </span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #0000BB">$insertTable</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$ret </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_last_insert_id</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /> if(</span><span style="color: #0000BB">$ret</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"Last Insert ID is : " </span><span style="color: #007700">. </span><span style="color: #0000BB">$ret </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /> } else {<br /> echo </span><span style="color: #DD0000">"No Last insert ID.\n"</span><span style="color: #007700">;<br /> }<br /> <br /> </span><span style="color: #0000BB">db2_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br />}<br />else {<br /> echo </span><span style="color: #DD0000">"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>
|
|
Last Insert ID is : 1
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
</div></div></div></body></html> |