代码
<?php
// 数据查询体验
class SearchAction extends Action{
function _initialize() {
// 为了方便使用dump函数查看结果输出,在初始化方法里统一编码
header("Content-Type:text/html; charset=utf-8");
}
// 使用find方法查询1
public function find1(){
// 实例化模型
$dao = D('Message');
// 查询id为3的记录
$rs = $dao->
find(3);
// 输出结果
dump ( $rs );
// 输出sql语句进行对比
dump( $dao->getLastSql() );
}
// 使用find方法查询2
public function find2() {
// 实例化模型
$dao = D('Message');
// 设置查询条件
$where['status'] = 0;
$where['email'] = 'thinkphp@thinkphp.cn';
// 需要查询的字段
$field = 'email,title';
// 进行查询
$rs = $dao->where($where)->field($field)->find();
// 输出结果
dump ( $rs );
// 输出sql语句进行
dump( $dao->getLastSql() );
}
// 获取所有记录集
public function select1() {
// 实例化模型
$dao = D('Message');
// 设置查询条件
$where['status'] = 1;
// 需要查询的字段
$field = 'email,title';
// 进行查询
$rs = $dao->where($where)->field($field)->select();
// 输出结果
dump ( $rs );
// 输出sql语句进行
dump( $dao->getLastSql() );
}
}//类定义 end
?>