The following example issues a SELECT statement with a scalar function,
RTRIM, that removes whitespace from the end of the column. Rather than
creating an object with the properties "BREED" and "2", we use the AS
clause in the SELECT statement to assign the name "name" to the modified
column. The database server folds the column names to upper-case,
resulting in an object with the properties "BREED" and "NAME".
<?php
$conn = db2_connect($database, $user, $password);
$sql = "SELECT breed, RTRIM(name) AS name
FROM animals
WHERE id = ?";
if ($conn) {
$stmt = db2_prepare($conn, $sql);
db2_execute($stmt, array(0));
while ($pet = db2_fetch_object($stmt)) {
echo "Come here, {$pet->NAME}, my little {$pet->BREED}!";
}
db2_close($conn);
}
?>
The above example will output:
Come here, Pook, my little cat!