phpBugTracker | ||
---|---|---|
Prev | Chapter 3. Developer's Guide |
PHPlib can be found at http://phplib.sourceforge.net. It provides the database abstraction layer, html templates, and session and authentication management.
Instead of using PHP's database functions directly, interactions are done via database objects, which extend PHPlib's DB_Sql class.
The global variable $q is available as an instance of the class dbclass. This class adds two functions to the DB_Sql class, grab() and grab_field(). If they are called with an argument, the argument is passed as a query to the database and the results are returned from that query. If no argument is passed, they return results from the previous call to query(). Here are some examples:
// Grab one field from one record in the database $user_email = $q->grab_field("select email from ".TBL_AUTH_USER." where user_id = 1"); echo $user_email; // Stuff all the fields from a user record into an array $user_info = $q->grab("select * from ".TBL_AUTH_USER." where user_id = 1"); echo $user_info['email']; // Work with a set of records $q->query("select * from ".TBL_AUTH_USER); while ($row = $q->grab()) { echo $row['email'].'<br>'; } |
Instead of outputting HTML from the scripts, templates are used to separate the code from the HTML. The templates contain tokens that are replaced by the scripts with values. The general process for using templates is as follows:
// Set up the file to be used $t->set_file('content', 'bugdisplay.html'); // Substitute the tokens with data $t->set_var(array( 'title' => $buginfo['title'], 'description' => $buginfo['description'], .... )); // Parse the template and print it out (inside a wrap template) $t->pparse('main', array('content', 'wrap', 'main'); |