Introduction - Query -- Performing a queries
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
DB_Error
object, check it with
DB::isError(). On success you get
DB_OK or
when you set a SELECT-statment a
DB_result object.
Example 21-1. Doing a query <?php
// Once you have a valid DB object...
$sql = "select * from clients";
$result =& $db->query($sql);
// Always check that $result is not an error
if (DB::isError($result)) {
die ($result->getMessage());
}
....
?> |
|
query() can be used instead of
prepare() and
execute(), if you
set the $params parameter
and your query uses placeholders.