L'exemple suivant utilise la fonction db2_exec() pour
     envoyer un ensemble de requêtes DDL afin de créer une table.
    
<?php
$conn = db2_connect($database, $user, $password);
// Create the test table
$create = 'CREATE TABLE animaux (id INTEGER, race VARCHAR(32),
    nom CHAR(16), poids DECIMAL(7,2))';
$result = db2_exec($conn, $create);
if ($result) {
    print "La table a été créée correctement.\n";
}
// Remplit la table de test
$animaux = array(
    array(0, 'chat', 'Pook', 3.2),
    array(1, 'chien', 'Peaches', 12.3),
    array(2, 'cheval', 'Smarty', 350.0),
    array(3, 'cyprin doré', 'Bubbles', 0.1),
    array(4, 'perruche', 'Gizmo', 0.2),
    array(5, 'chèvre', 'Rickety Ride', 9.7),
    array(6, 'lama', 'Sweater', 150)
);
foreach ($animaux as $animal) {
    $rc = db2_exec($conn, "INSERT INTO animaux (id, race, nom, poids)
      VALUES ({$animal[0]}, '{$animal[1]}', '{$animal[2]}', {$animal[3]})");
    if ($rc) {
        print "Insertion... ";
    }
}
?>
     
    L'exemple ci-dessus va afficher :
La table a été créée correctement.
Insertion... Insertion... Insertion... Insertion... Insertion... Insertion... Insertion...