function.db2-execute.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 258 行 · 第 1/2 页
HTML
258 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Executes a prepared SQL statement</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.db2-exec.html">db2_exec</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.db2-fetch-array.html">db2_fetch_array</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-execute" class="refentry"> <div class="refnamediv"> <h1 class="refname">db2_execute</h1> <p class="verinfo">(PECL ibm_db2:1.0-1.6.2)</p><p class="refpurpose"><span class="refname">db2_execute</span> — <span class="dc-title"> Executes a prepared SQL statement </span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><b><b>db2_execute</b></b></span> ( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$stmt</tt></span> [, <span class="methodparam"><span class="type">array</span> <tt class="parameter">$parameters</tt></span> ] )</div> <p class="para rdfs-comment"> <b>db2_execute()</b> executes an SQL statement that was prepared by <a href="function.db2-prepare.html" class="function">db2_prepare()</a>. </p> <p class="para"> If the SQL statement returns a result set, for example, a SELECT statement or a CALL to a stored procedure that returns one or more result sets, you can retrieve a row as an array from the <i>stmt</i> resource using <a href="function.db2-fetch-assoc.html" class="function">db2_fetch_assoc()</a>, <a href="function.db2-fetch-both.html" class="function">db2_fetch_both()</a>, or <a href="function.db2-fetch-array.html" class="function">db2_fetch_array()</a>. Alternatively, you can use <a href="function.db2-fetch-row.html" class="function">db2_fetch_row()</a> to move the result set pointer to the next row and fetch a column at a time from that row with <a href="function.db2-result.html" class="function">db2_result()</a>. </p> <p class="para"> Refer to <a href="function.db2-prepare.html" class="function">db2_prepare()</a> for a brief discussion of the advantages of using <a href="function.db2-prepare.html" class="function">db2_prepare()</a> and <b>db2_execute()</b> rather than <a href="function.db2-exec.html" class="function">db2_exec()</a>. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">stmt</tt></i></span> <dd> <p class="para"> A prepared statement returned from <a href="function.db2-prepare.html" class="function">db2_prepare()</a>. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">parameters</tt></i></span> <dd> <p class="para"> An array of input parameters matching any parameter markers contained in the prepared statement. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <b><tt>TRUE</tt></b> on success or <b><tt>FALSE</tt></b> on failure. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 Preparing and executing an SQL statement with parameter markers</b></p> <div class="example-contents"><p> The following example prepares an INSERT statement that accepts four parameter markers, then iterates over an array of arrays containing the input values to be passed to <b>db2_execute()</b>. </p></div> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$pet </span><span style="color: #007700">= array(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #DD0000">'cat'</span><span style="color: #007700">, </span><span style="color: #DD0000">'Pook'</span><span style="color: #007700">, </span><span style="color: #0000BB">3.2</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$insert </span><span style="color: #007700">= </span><span style="color: #DD0000">'INSERT INTO animals (id, breed, name, weight)<br /> VALUES (?, ?, ?, ?)'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #0000BB">$insert</span><span style="color: #007700">);<br />if (</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">, </span><span style="color: #0000BB">$pet</span><span style="color: #007700">);<br /> if (</span><span style="color: #0000BB">$result</span><span style="color: #007700">) {<br /> print </span><span style="color: #DD0000">"Successfully added new pet."</span><span style="color: #007700">;<br /> }<br />}<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"><pre><div class="cdata"><pre>Successfully added new pet.</pre></div> </pre></div> </div> <div class="example"> <p><b>Example #2 Calling a stored procedure with an OUT parameter</b></p> <div class="example-contents"><p> The following example prepares a CALL statement that accepts one parameter marker representing an OUT parameter, binds the PHP variable <i>$my_pets</i> to the parameter using
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?