| 状态 | 草稿 |
|---|---|
| Todo | Proof read this page, check links |
| 官方最后更新时间 | 2008/05/01 20:31 |
数据库类是提供的数据库访问您的应用程序的的接口驱动。
目前支持下列的数据库驱动:
目录列表
以下代码实例使用了共同的数据库功能,为了更深入的说明,个别请联系上下文以及上面的目录列表的内容。
$db = new Database(); // 或者 $db = new Database('groupname'); // 如果 groupname 没有提供,"默认" 是假设的。
$result = $db->query('SELECT username,password,email FROM users'); foreach ($result as $row) { echo $row->username; echo $row->password; echo $row->email; }
这里实例是一个在模板中显示查询结果
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>