Add example for all parameter types to db2_bind_param().

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@197697 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Dan Scott 2005-10-05 21:00:31 +00:00
parent acc0216e9f
commit 7b9bc55d0e

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.6 $ -->
<!-- $Revision: 1.7 $ -->
<!-- Generated by xml_proto.php v2.2. Found in /scripts directory of phpdoc. -->
<refentry id="function.db2-bind-param">
<refnamediv>
@ -164,6 +164,83 @@ Peaches, dog, 12.3
]]>
</screen>
</example>
<example>
<title>Calling stored procedures with IN and OUT parameters</title>
<para>
The stored procedure match_animal in the following example accepts
three different parameters:
<orderedlist>
<listitem>
<para>
an input (IN) parameter that accepts the name of the first animal as
input
</para>
</listitem>
<listitem>
<para>
an input-output (INOUT) parameter that accepts the name of the second
animal as input and returns the string <literal>TRUE</literal> if an
animal in the database matches that name
</para>
</listitem>
<listitem>
<para>
an output (OUT) parameter that returns the sum of the weight of the
two identified animals
</para>
</listitem>
</orderedlist>
In addition, the stored procedure returns a result set consisting of the
animals listed in alphabetic order starting at the animal corresponding
to the input value of the first parameter and ending at the animal
corresponding to the input value of the second parameter.
</para>
<programlisting role="php">
<![CDATA[
<?php
$sql = 'CALL match_animal(?, ?, ?)';
$conn = db2_connect($database, $user, $password);
$stmt = db2_prepare($conn, $sql);
$name = "Peaches";
$second_name = "Rickety Ride";
db2_bind_param($stmt, 1, "name", DB2_PARAM_IN);
db2_bind_param($stmt, 2, "second_name", DB2_PARAM_INOUT);
db2_bind_param($stmt, 3, "weight", DB2_PARAM_OUT);
print "Values of bound parameters _before_ CALL:\n";
print " {$name} {$second_name} {$weight}\n\n";
if (db2_execute($stmt)) {
print "Values of bound parameters _after_ CALL:\n";
print " 1: {$name} 2: {$second_name} 3: {$weight}\n\n";
print "Results:\n";
while ($row = db2_fetch_array($stmt)) {
print " {$row[0]}, {$row[1]}, {$row[2]}\n";
}
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Values of bound parameters _before_ CALL:
1: Peaches 2: Rickety Ride 3:
Values of bound parameters _after_ CALL:
1: Peaches 2: Rickety Ride 3:
Results:
Peaches, dog, 12.3
Pook, cat, 3.2
Rickety Ride, goat, 9.7
]]>
</screen>
</example>
</para>
</refsect1>