获取数据
OOP_ORM_Result Module_OOP_ORM_Finder_DB::find( [ string $sql = null , boolean $use_master = null ] )
参数列表
参数 类型 描述 默认值 $sql
string
指定SQL语句,不传则使用QueryBulider构造 null $use_master
boolean
查询是否用主数据库 null
OOP_ORM_Result
public function find($sql = null , $use_master = null)
{
if ( $sql )
{
$data = $this->driver()->query($sql , false , $use_master)->as_array();
}
else
{
$bulider = & $this->driver()->get_builder();
if ( !$bulider['from'] )
{
$this->driver()->from($this->tablename);
}
if ( $this->_auto_where )
{
$this->driver()->where($this->_auto_where);
}
$id_cache_data = null;
# 优化主键数据查询
$not_need_find = $this->_get_id_field_cache_data($bulider , $id_cache_data);
unset($bulider);
if (false===$not_need_find)
{
$data = $this->driver()->get(false , $use_master)->as_array();
if ( null!==$id_cache_data )
{
$data += $id_cache_data;
}
}
else
{
$this->driver()->reset();
$data = $id_cache_data;
}
}
# 最后查询SQL
$this->last_query = $this->driver()->last_query();
$obj = $this->create_group_data($data, true);
return $obj;
}