| Status | Draft |
|---|---|
| Todo | Proof read this page, check links |
The database library provides database access to your application using drivers.
Currently we have the following drivers available:
The following is example code for using common database functionality. For more in depth help please read the individual topics linked above.
$db = new Database(); // or $db = new Database('groupname'); // "default" is assumed if groupname is not given
$result = $db->query('SELECT username,password,email FROM users'); foreach ($result as $row) { echo $row->username; echo $row->password; echo $row->email; }
This demonstrates using the query results in a template.
class Clients_Controller extends Controller { public function index() { $db = new Database; $result = $db->query('SELECT name, code FROM clients'); $v = new View('clients'); $v->result = $result; $v->render(TRUE); } }
<html> <head> <style> /* * Zebra rows: When CSS3 is done we could simply use: * tr :nth-child(odd) { background-color: #D0D0D0; } * but for now we use PHP and CSS */ table.db tr { background-color: #F0F0F0; } table.db tr.odd { background-color: #D0D0D0; } table.db th { color: #f0f0f0; background-color: #303030; } </style> </head> <body> <h2>Client List</h2> <hr/> <table class="db"> <tr> <th>Client</th> <th>ID</th> </tr> <?php foreach( $result as $row ):?> <tr <?= text::alternate( '', ' class="odd"' ) ?>> <td><?= $row->name ?> </td> <td><?= $row->code ?> </td> </tr> <?php endforeach; ?> </table> </body>