Databases Reference
In-Depth Information
Example 6-17 sample PHP code to test DB2
<?php
$conn = db2_connect('sample', 'userid', 'password');
$create = 'DROP TABLE xmlTest';
$result = db2_exec($conn, $create);
$create = 'CREATE TABLE xmlTest (id INTEGER, data XML)';
$result = db2_exec($conn, $create);
$insert = "INSERT INTO xmlTest values (0,
'<Client><Address><street>555 Bailey Ave</street><city>San
Jose</city><state>CA</state><zip>95141</zip></Address><email>ranjanr
@us.ibm.com</email></Client>')";
db2_exec( $conn, $insert );
if ($conn) {
$sql = "SELECT data FROM xmlTest";
$stmt = db2_prepare( $conn, $sql );
db2_execute($stmt);
while($result = db2_fetch_assoc($stmt)) {
print_r($result);
echo "\n";
}
db2_close($conn);
} else {
echo "Connection failed.\n";
}
?>
Save this file in any folder(for example, C:\rakesh\test.php) and run it:
php test.php
You should be able to see the result as shown in Example 6-18 on page 310.
Example 6-18 Output of test.php
C:\rakesh>php test.php
Array
(
[DATA] => <?xml version="1.0" encoding="UTF-8"
?><Client><Address><street>555 Bailey Ave</street><city>San
Jose</cit
y><state>CA</state><zip>95141</zip></Address><email>ranjanr@us.ibm.c
om</email></Client>
)
Search WWH ::




Custom Search