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.
<?php // Create a valid DB object named $db // at the beginning of your program... require_once 'DB.php'; $db =& DB::connect('pgsql://usr:pw@localhost/dbnam'); if (DB::isError($db)) { die($db->getMessage()); } // Proceed with a query... $result =& $db->query('SELECT * FROM clients'); // 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.
<?php // Once you have a valid DB object named $db... $sql = 'select * from clients where clientid = ?'; $data = 53; $result =& $db->query($sql, $data); // Always check that $result is not an error if (DB::isError($result)) { die($result->getMessage()); } .... ?>
<?php // Once you have a valid DB object named $db... $sql = 'select * from clients where clientid = ? and statusid = ?'; $data = array(53, 4); $result =& $db->query($sql, $data); // Always check that $result is not an error if (DB::isError($result)) { die($result->getMessage()); } .... ?>
Deliver First Class Web Sites: 101 Essential Checklists Want to learn how to make your web sites usable and accessible? Want to ensure that your sites meet current best practice, without spending hours trawling through incomprehensible specifications and recommendations from dozens of different books, research papers, and web sites? Want to make sure that the sites you build are "right the first time," requiring no costly redevelopments?