PEAR::DB replacement class

Contents

The query() method

This is the main query method. It's commonly used for non select type queries. It's also used by the shortcut get* methods It can return two types, a DB_error or a DB_result. Both of them are objects.

Example

<php
    $result = $db->query("SELECT a, b, c FROM myTable");
?>

Here, $result will be a DB_result object thus you'll be able to use it a loop (eg. a while loop) to loop through the results. Eg:

<?php
    $result = $db->query("SELECT a, b, c FROM myTable");

    while ($row = $result->fetchRow()) {
        ...
    }
?>

If you want to refer to the result sets columns associatively (eg. for readability) you can pass the appropriate constant to this method. This will override the default fetch mode. Eg:

<?php
    $result = $db->query("SELECT a, b, c FROM myTable");

    while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
        ...
    }
?>