PEAR Manual
Prev |  | Next

# Introduction - Query

Introduction - Query -- Performing a query against a database.

## Description

To perform a query against a database, you have to use the function query(), that takes the query string as an argument. On failure you get a MDB_Error object. Be sure to check it with MDB::isError(). On success, you get `MDB_OK` or when you set a `SELECT`-statment a result resource handle

Example 33-1. A simple MDB query
    <?php
    // Once you have a valid MDB object...
    $sql = "select * from clients";

    $result = $db->query($sql);

    // Always check that $result is not an error
    if (MDB::isError($result)) {
        die ($result->getMessage());
    }

    // Continue on with your script
    ?>

Prev | Home | Next
Introduction - Connect | Up | Introduction - Fetch