qeephp中操作数据库的几种方法

1.用orm(对象关系映射)方式。

 $temp= Task::find()->getAll();

2. 表数据入口。和flea 的TableDataGateway一样。
name 为表名

$table = new QDB_Table(array('name'=>'tasks'));
 dump(
$table ->select()->getAll());

3.直接使用sql语句。
getConne为获得一个数据库连接对象,如果为空则获得默认数据库连接对应的数据库访问对象,
// 获得数据库连接信息 db_dsn_pool/news_db 对应的数据库访问对象 $dbo_news = QDB::getConn(’news_db’);

   $table =QDB::getConn();
   
$sql = "SELECT * FROM tasks";
   
$handel =$table->execute($sql);
   
$temp = $handel->fetchAll();
    
$handel->free();
  dump(
$temp);

 

第一种反法的结果为
Array
(
[0] => Task Object
(
[_props:protected] => Array
(
[task_id] => 1
[created] => 1233567142
[updated] => 1233736732
[is_completed] => 0
[completed_at] =>
[user] =>
[subject] => task
[description] => renwu
[owner_id] => 1
)

[_class_name:protected] => Task
[_id:protected] =>
[_changed_props:private] => Array
(
)

[__exception_trap] => Array
(
)

)

输出的是对象模型。
2和3得到的结果是:
Array
(
[0] => Array
(
[task_id] => 1
[subject] => task
[description] => renwu
[created] => 1233567142
[updated] => 1233736732
[is_completed] => 0
[completed_at] =>
[owner_id] => 1
)
输出的是表的数据

posted @ 2009-09-16 23:01  phpzxh  阅读(1392)  评论(2编辑  收藏  举报