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


resource prepare ( string $query )


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


string $query

the query to prepare

Return value

resource - the query handle or a DB_Error object on failure


This function can not be called statically.


Using prepare()

// Once you have a valid DB object named $db...
$sth $db->prepare('INSERT INTO numbers (number) VALUES (?)');
if (
PEAR::isError($sth)) {

$res =& $db->execute($sth1);
if (
PEAR::isError($res)) {
Informs the DB driver that the next query is a manipulation query (Previous) Checks if the DBMS supports a particular feature (Next)
Last updated: Sat, 03 Oct 2015 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

Note by: user2037
It may not be obvious but you need to "escape placeholder characters" such as question marks, exclamation points, and ampersands when preparing a query. For example: "SELECT * WHERE a \!= FALSE AND b = ?".