Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 5810

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>db2_exec</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="IBM DB2, Cloudscape and Apache Derby Functions"
HREF="ref.ibm-db2.html"><LINK
REL="PREVIOUS"
TITLE="db2_escape_string"
HREF="function.db2-escape-string.html"><LINK
REL="NEXT"
TITLE="db2_execute"
HREF="function.db2-execute.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP 手册</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.db2-escape-string.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.db2-execute.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.db2-exec"
></A
>db2_exec</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN80508"
></A
><P
>    (PECL)</P
>db2_exec&nbsp;--&nbsp;
   Executes an SQL statement directly
  </DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN80511"
></A
><H2
>说明</H2
>resource <B
CLASS="methodname"
>db2_exec</B
> ( resource connection, string statement [, array options] )<BR
></BR
><P
>&#13;   Executes an SQL statement directly.
  </P
><P
>&#13;   If you plan to interpolate PHP variables into the SQL statement, understand
   that this is one of the more common security exposures. Consider calling
   <A
HREF="function.db2-prepare.html"
><B
CLASS="function"
>db2_prepare()</B
></A
> to prepare an SQL statement with parameter
   markers for input values. Then you can call <A
HREF="function.db2-execute.html"
><B
CLASS="function"
>db2_execute()</B
></A
>
   to pass in the input values and avoid SQL injection attacks.
  </P
><P
>&#13;   If you plan to repeatedly issue the same SQL statement with different
   parameters, consider calling <A
HREF="function.db2-prepare.html"
><B
CLASS="function"
>db2_prepare()</B
></A
> and
   <A
HREF="function.db2-execute.html"
><B
CLASS="function"
>db2_execute()</B
></A
> to enable the database server to reuse its
   access plan and increase the efficiency of your database access.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN80532"
></A
><H2
>参数</H2
><P
>&#13;   <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><CODE
CLASS="parameter"
>connection</CODE
></DT
><DD
><P
>&#13;       A valid database connection resource variable as returned from
       <A
HREF="function.db2-connect.html"
><B
CLASS="function"
>db2_connect()</B
></A
> or <A
HREF="function.db2-pconnect.html"
><B
CLASS="function"
>db2_pconnect()</B
></A
>.
      </P
></DD
><DT
><CODE
CLASS="parameter"
>statement</CODE
></DT
><DD
><P
>&#13;       An SQL statement. The statement cannot contain any parameter markers.
      </P
></DD
><DT
><CODE
CLASS="parameter"
>options</CODE
></DT
><DD
><P
>&#13;       An associative array containing statement options. You can use this
       parameter to request a scrollable cursor on database servers that
       support this functionality.
       <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><CODE
CLASS="parameter"
>cursor</CODE
></DT
><DD
><P
>&#13;           Passing the <TT
CLASS="literal"
>DB2_FORWARD_ONLY</TT
> value requests a
           forward-only cursor for this SQL statement. This is the default
           type of cursor, and it is supported by all database servers. It is
           also much faster than a scrollable cursor.
          </P
><P
>&#13;           Passing the <TT
CLASS="literal"
>DB2_SCROLLABLE</TT
> value requests a
           scrollable cursor for this SQL statement. This type of cursor
           enables you to fetch rows non-sequentially from the database
           server. However, it is only supported by DB2 servers, and is much
           slower than forward-only cursors.
          </P
></DD
></DL
></DIV
>

      </P
></DD
></DL
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN80562"
></A
><H2
>返回值</H2
><P
>&#13;   Returns a statement resource if the SQL statement was issued successfully,
   or <TT
CLASS="constant"
><B
>FALSE</B
></TT
> if the database failed to execute the SQL statement.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN80566"
></A
><H2
>范例</H2
><P
>&#13;   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN80569"
></A
><P
><B
>例 1. Creating a table with <B
CLASS="function"
>db2_exec()</B
></B
></P
><P
>&#13;     The following example uses <B
CLASS="function"
>db2_exec()</B
> to issue a set
     of DDL statements in the process of creating a table.
    </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$conn </font><font color="#007700">= </font><font color="#0000BB">db2_connect</font><font color="#007700">(</font><font color="#0000BB">$database</font><font color="#007700">, </font><font color="#0000BB">$user</font><font color="#007700">, </font><font color="#0000BB">$password</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// Create the test table<br /></font><font color="#0000BB">$create </font><font color="#007700">= </font><font color="#DD0000">'CREATE TABLE animals (id INTEGER, breed VARCHAR(32),<br />&nbsp;&nbsp;&nbsp;&nbsp;name CHAR(16), weight DECIMAL(7,2))'</font><font color="#007700">;<br /></font><font color="#0000BB">$result </font><font color="#007700">= </font><font color="#0000BB">db2_exec</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#0000BB">$create</font><font color="#007700">);<br />if (</font><font color="#0000BB">$result</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;print </font><font color="#DD0000">"Successfully created the table.\n"</font><font color="#007700">;<br />}<br /><br /></font><font color="#FF8000">// Populate the test table<br /></font><font color="#0000BB">$animals </font><font color="#007700">= array(<br />&nbsp;&nbsp;&nbsp;&nbsp;array(</font><font color="#0000BB">0</font><font color="#007700">, </font><font color="#DD0000">'cat'</font><font color="#007700">, </font><font color="#DD0000">'Pook'</font><font color="#007700">, </font><font color="#0000BB">3.2</font><font color="#007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;array(</font><font color="#0000BB">1</font><font color="#007700">, </font><font color="#DD0000">'dog'</font><font color="#007700">, </font><font color="#DD0000">'Peaches'</font><font color="#007700">, </font><font color="#0000BB">12.3</font><font color="#007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;array(</font><font color="#0000BB">2</font><font color="#007700">, </font><font color="#DD0000">'horse'</font><font color="#007700">, </font><font color="#DD0000">'Smarty'</font><font color="#007700">, </font><font color="#0000BB">350.0</font><font color="#007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;array(</font><font color="#0000BB">3</font><font color="#007700">, </font><font color="#DD0000">'gold fish'</font><font color="#007700">, </font><font color="#DD0000">'Bubbles'</font><font color="#007700">, </font><font color="#0000BB">0.1</font><font color="#007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;array(</font><font color="#0000BB">4</font><font color="#007700">, </font><font color="#DD0000">'budgerigar'</font><font color="#007700">, </font><font color="#DD0000">'Gizmo'</font><font color="#007700">, </font><font color="#0000BB">0.2</font><font color="#007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;array(</font><font color="#0000BB">5</font><font color="#007700">, </font><font color="#DD0000">'goat'</font><font color="#007700">, </font><font color="#DD0000">'Rickety Ride'</font><font color="#007700">, </font><font color="#0000BB">9.7</font><font color="#007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;array(</font><font color="#0000BB">6</font><font color="#007700">, </font><font color="#DD0000">'llama'</font><font color="#007700">, </font><font color="#DD0000">'Sweater'</font><font color="#007700">, </font><font color="#0000BB">150</font><font color="#007700">)<br />);<br /><br />foreach (</font><font color="#0000BB">$animals </font><font color="#007700">as </font><font color="#0000BB">$animal</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$rc </font><font color="#007700">= </font><font color="#0000BB">db2_exec</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#DD0000">"INSERT INTO animals (id, breed, name, weight)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VALUES (</font><font color="#007700">{</font><font color="#DD0000">$animal</font><font color="#007700">[</font><font color="#DD0000">0</font><font color="#007700">]}</font><font color="#DD0000">, '</font><font color="#007700">{</font><font color="#DD0000">$animal</font><font color="#007700">[</font><font color="#DD0000">1</font><font color="#007700">]}</font><font color="#DD0000">', '</font><font color="#007700">{</font><font color="#DD0000">$animal</font><font color="#007700">[</font><font color="#DD0000">2</font><font color="#007700">]}</font><font color="#DD0000">', </font><font color="#007700">{</font><font color="#DD0000">$animal</font><font color="#007700">[</font><font color="#DD0000">3</font><font color="#007700">]}</font><font color="#DD0000">)"</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;if (</font><font color="#0000BB">$rc</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print </font><font color="#DD0000">"Insert... "</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>Successfully created the table.
Insert... Insert... Insert... Insert... Insert... Insert... Insert...</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>

   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN80577"
></A
><P
><B
>例 2. Executing a SELECT statement with a scrollable cursor</B
></P
><P
>&#13;     The following example demonstrates how to request a scrollable cursor for
     an SQL statement issued by <B
CLASS="function"
>db2_exec()</B
>.
    </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$conn </font><font color="#007700">= </font><font color="#0000BB">db2_connect</font><font color="#007700">(</font><font color="#0000BB">$database</font><font color="#007700">, </font><font color="#0000BB">$user</font><font color="#007700">, </font><font color="#0000BB">$password</font><font color="#007700">);<br /></font><font color="#0000BB">$sql </font><font color="#007700">= </font><font color="#DD0000">"SELECT name FROM animals<br />&nbsp;&nbsp;&nbsp;&nbsp;WHERE weight &lt; 10.0<br />&nbsp;&nbsp;&nbsp;&nbsp;ORDER BY name"</font><font color="#007700">;<br />if (</font><font color="#0000BB">$conn</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;require_once(</font><font color="#DD0000">'prepare.inc'</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">db2_exec</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#0000BB">$sql</font><font color="#007700">, array(</font><font color="#DD0000">'cursor' </font><font color="#007700">=&gt; </font><font color="#0000BB">DB2_SCROLLABLE</font><font color="#007700">));<br />&nbsp;&nbsp;&nbsp;&nbsp;while (</font><font color="#0000BB">$row </font><font color="#007700">= </font><font color="#0000BB">db2_fetch_array</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print </font><font color="#DD0000">"$row</font><font color="#007700">[</font><font color="#DD0000">0</font><font color="#007700">]\n</font><font color="#DD0000">"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />} <br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>Bubbles
Gizmo
Pook
Rickety Ride</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN80584"
></A
><P
><B
>例 3. Returning XML data as a SQL ResultSet</B
></P
><P
>&#13;     The following example demonstrates how to work with documents stored 
     in a XML column using the SAMPLE database. Using some pretty simple 
     SQL/XML, this example returns some of the nodes in a XML document in 
     a SQL ResultSet format that most users are familiar with.
    </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />$conn </font><font color="#007700">= </font><font color="#0000BB">db2_connect</font><font color="#007700">(</font><font color="#DD0000">"SAMPLE"</font><font color="#007700">, </font><font color="#DD0000">"db2inst1"</font><font color="#007700">, </font><font color="#DD0000">"ibmdb2"</font><font color="#007700">);<br /><br /></font><font color="#0000BB">$query </font><font color="#007700">= </font><font color="#DD0000">'SELECT * FROM XMLTABLE(<br />&nbsp;&nbsp;&nbsp;&nbsp;XMLNAMESPACES (DEFAULT \'http://posample.org\'),<br />&nbsp;&nbsp;&nbsp;&nbsp;\'db2-fn:xmlcolumn("CUSTOMER.INFO")/customerinfo\'<br />&nbsp;&nbsp;&nbsp;&nbsp;COLUMNS<br />&nbsp;&nbsp;&nbsp;&nbsp;"CID" VARCHAR (50) PATH \'@Cid\',<br />&nbsp;&nbsp;&nbsp;&nbsp;"NAME" VARCHAR (50) PATH \'name\',<br />&nbsp;&nbsp;&nbsp;&nbsp;"PHONE" VARCHAR (50) PATH \'phone [ @type = "work"]\'<br />&nbsp;&nbsp;&nbsp;&nbsp;) AS T<br />&nbsp;&nbsp;&nbsp;&nbsp;WHERE NAME = \'Kathy Smith\'<br />&nbsp;&nbsp;&nbsp;&nbsp;'</font><font color="#007700">;<br /></font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">db2_exec</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#0000BB">$query</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />while(</font><font color="#0000BB">$row </font><font color="#007700">= </font><font color="#0000BB">db2_fetch_object</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">)){<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">printf</font><font color="#007700">(</font><font color="#DD0000">"$row</font><font color="#007700">-&gt;</font><font color="#DD0000">CID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$row</font><font color="#007700">-&gt;</font><font color="#DD0000">NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$row</font><font color="#007700">-&gt;</font><font color="#DD0000">PHONE</font><font color="#007700">\n</font><font color="#DD0000">"</font><font color="#007700">);<br />}<br /></font><font color="#0000BB">db2_close</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">);<br /><br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>1000     Kathy Smith     416-555-1358
1001     Kathy Smith     905-555-7258</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN80590"
></A
><P
><B
>例 4. Performing a "JOIN" with XML data</B
></P
><P
>&#13;     The following example works with documents stored in 2 different 
     XML columns in the SAMPLE database. It creates 2 temporary 
     tables from the XML documents from 2 different columns and 
     returns a SQL ResultSet with information regarding shipping 
     status for the customer.
    </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />$conn </font><font color="#007700">= </font><font color="#0000BB">db2_connect</font><font color="#007700">(</font><font color="#DD0000">"SAMPLE"</font><font color="#007700">, </font><font color="#DD0000">"db2inst1"</font><font color="#007700">, </font><font color="#DD0000">"ibmdb2"</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;<br /></font><font color="#0000BB">$query </font><font color="#007700">= </font><font color="#DD0000">'<br />&nbsp;&nbsp;&nbsp;&nbsp;SELECT A.CID, A.NAME, A.PHONE, C.PONUM, C.STATUS<br />&nbsp;&nbsp;&nbsp;&nbsp;FROM<br />&nbsp;&nbsp;&nbsp;&nbsp;XMLTABLE(<br />&nbsp;&nbsp;&nbsp;&nbsp;XMLNAMESPACES (DEFAULT \'http://posample.org\'),<br />&nbsp;&nbsp;&nbsp;&nbsp;\'db2-fn:xmlcolumn("CUSTOMER.INFO")/customerinfo\'<br />&nbsp;&nbsp;&nbsp;&nbsp;COLUMNS<br />&nbsp;&nbsp;&nbsp;&nbsp;"CID" BIGINT PATH \'@Cid\',<br />&nbsp;&nbsp;&nbsp;&nbsp;"NAME" VARCHAR (50) PATH \'name\',<br />&nbsp;&nbsp;&nbsp;&nbsp;"PHONE" VARCHAR (50) PATH \'phone [ @type = "work"]\'<br />&nbsp;&nbsp;&nbsp;&nbsp;) as A,<br />&nbsp;&nbsp;&nbsp;&nbsp;PURCHASEORDER AS B,<br />&nbsp;&nbsp;&nbsp;&nbsp;XMLTABLE (<br />&nbsp;&nbsp;&nbsp;&nbsp;XMLNAMESPACES (DEFAULT \'http://posample.org\'),<br />&nbsp;&nbsp;&nbsp;&nbsp;\'db2-fn:xmlcolumn("PURCHASEORDER.PORDER")/PurchaseOrder\'<br />&nbsp;&nbsp;&nbsp;&nbsp;COLUMNS<br />&nbsp;&nbsp;&nbsp;&nbsp;"PONUM"&nbsp;&nbsp;BIGINT PATH \'@PoNum\',<br />&nbsp;&nbsp;&nbsp;&nbsp;"STATUS" VARCHAR (50) PATH \'@Status\'<br />&nbsp;&nbsp;&nbsp;&nbsp;) as C<br />&nbsp;&nbsp;&nbsp;&nbsp;WHERE A.CID = B.CUSTID AND<br />&nbsp;&nbsp;&nbsp;&nbsp;B.POID = C.PONUM AND<br />&nbsp;&nbsp;&nbsp;&nbsp;A.NAME = \'Kathy Smith\'<br />'</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br /></font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">db2_exec</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#0000BB">$query</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />while(</font><font color="#0000BB">$row </font><font color="#007700">= </font><font color="#0000BB">db2_fetch_object</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">)){<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">printf</font><font color="#007700">(</font><font color="#DD0000">"$row</font><font color="#007700">-&gt;</font><font color="#DD0000">CID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$row</font><font color="#007700">-&gt;</font><font color="#DD0000">NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$row</font><font color="#007700">-&gt;</font><font color="#DD0000">PHONE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$row</font><font color="#007700">-&gt;</font><font color="#DD0000">PONUM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$row</font><font color="#007700">-&gt;</font><font color="#DD0000">STATUS</font><font color="#007700">\n</font><font color="#DD0000">"</font><font color="#007700">);<br />}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br /></font><font color="#0000BB">db2_close</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">);<br /><br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>1001     Kathy Smith     905-555-7258     5002     Shipped</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN80596"
></A
><P
><B
>例 5. Returning SQL data as part of a larger XML document</B
></P
><P
>&#13;     The following example works with a portion of the PRODUCT.DESCRIPTION 
     documents in the SAMPLE database. It creates a XML document containing 
     product description (XML data) and pricing info (SQL data).
    </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /><br />$conn </font><font color="#007700">= </font><font color="#0000BB">db2_connect</font><font color="#007700">(</font><font color="#DD0000">"SAMPLE"</font><font color="#007700">, </font><font color="#DD0000">"db2inst1"</font><font color="#007700">, </font><font color="#DD0000">"ibmdb2"</font><font color="#007700">);<br /><br /></font><font color="#0000BB">$query </font><font color="#007700">= </font><font color="#DD0000">'<br />SELECT<br />XMLSERIALIZE(<br />XMLQUERY(\'<br />&nbsp;&nbsp;&nbsp;&nbsp;declare boundary-space strip;<br />&nbsp;&nbsp;&nbsp;&nbsp;declare default element namespace "http://posample.org";<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;promoList&gt; {<br />&nbsp;&nbsp;&nbsp;&nbsp;for $prod in $doc/product<br />&nbsp;&nbsp;&nbsp;&nbsp;where $prod/description/price &lt; 10.00<br />&nbsp;&nbsp;&nbsp;&nbsp;order by $prod/description/price ascending<br />&nbsp;&nbsp;&nbsp;&nbsp;return(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;promoitem&gt; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$prod,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;startdate&gt; {$start} &lt;/startdate&gt;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;enddate&gt; {$end} &lt;/enddate&gt;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;promoprice&gt; {$promo} &lt;/promoprice&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &lt;/promoitem&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;} &lt;/promoList&gt;<br />\' passing by ref DESCRIPTION AS "doc",<br />PROMOSTART as "start",<br />PROMOEND as "end",<br />PROMOPRICE as "promo"<br />RETURNING SEQUENCE)<br />AS CLOB (32000))<br />AS NEW_PRODUCT_INFO<br />FROM PRODUCT<br />WHERE PID = \'100-100-01\'<br />'</font><font color="#007700">;<br /><br /></font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">db2_exec</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#0000BB">$query</font><font color="#007700">);<br /><br />while(</font><font color="#0000BB">$row </font><font color="#007700">= </font><font color="#0000BB">db2_fetch_array</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">)){<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">printf</font><font color="#007700">(</font><font color="#DD0000">"$row</font><font color="#007700">[</font><font color="#DD0000">0</font><font color="#007700">]\n</font><font color="#DD0000">"</font><font color="#007700">);<br />}<br /></font><font color="#0000BB">db2_close</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">);<br /><br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>&#60;promoList xmlns="http://posample.org"&#62;
    &#60;promoitem&#62;
    &#60;product pid="100-100-01"&#62;
        &#60;description&#62;
            &#60;name&#62;Snow Shovel, Basic 22 inch&#60;/name&#62;
            &#60;details&#62;Basic Snow Shovel, 22 inches wide, straight handle with D-Grip&#60;/details&#62;
            &#60;price&#62;9.99&#60;/price&#62;
            &#60;weight&#62;1 kg&#60;/weight&#62;
        &#60;/description&#62;
    &#60;/product&#62;
    &#60;startdate&#62;2004-11-19&#60;/startdate&#62;
    &#60;enddate&#62;2004-12-19&#60;/enddate&#62;
    &#60;promoprice&#62;7.25&#60;/promoprice&#62;
    &#60;/promoitem&#62;
&#60;/promoList&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN80602"
></A
><H2
>参见</H2
><P
>&#13;   <P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
><A
HREF="function.db2-execute.html"
><B
CLASS="function"
>db2_execute()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.db2-prepare.html"
><B
CLASS="function"
>db2_prepare()</B
></A
></TD
></TR
></TBODY
></TABLE
><P
></P
>
  </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.db2-escape-string.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>起始页</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.db2-execute.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>db2_escape_string</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.ibm-db2.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>db2_execute</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>