PEAR Manual
Prev |  | Next

# DB_common::prepare()

DB_common::prepare() -- Prepares a SQL statement for later execution

## Synopsis

``resource prepare` (string $query)`

## Description

Gets a SQL statement ready so it can be run by execute().

## Parameter

string `$query`

  the query to prepare

## Return value

resource - the query handle or a DB_Error object on failure

## Note

This function can not be called statically.

## Example

Example 33-1. Using prepare()
    <?php
    // Once you have a valid DB object named $db...
    $sth = $db->prepare('INSERT INTO numbers (number) VALUES (?)');
    if (PEAR::isError($sth)) {
        die($sth->getMessage());
    }

    $res =& $db->execute($sth, 1);
    if (PEAR::isError($res)) {
        die($res->getMessage());
    }
    ?>

## See

"Intro - Prepare & Execute", "Intro - autoPrepare & autoExecute", execute(), executeMultiple()

Prev | Home | Next
DB_common::nextId() | Up | DB_common::provides()