模型

模型使用方法

$this->model->table("mnh_user_address")
    ->where(['openid' => $this->openid])
    ->orderBy("id desc")
    ->findAll();


$date1 = '2017-04-25 16:00:25';
$date2 = '2017-05-25 16:00:25';

// 使用 ? 匹配替换变量
$this->model->table("mnh_orders")->where("deleted_at is null and created_at > ? and created_at <= ?", [$date1, $date2])
     ->findAll();

// 最后执行的SQL     
echo $this->model->sql;

模型方法

  • table($table_name)

  • dbconfig($db_config_name)

  • cache($expire)

  • select($field)

  • field($field)

  • limit($offset, $limit = 0)

  • set($data, $replacement = array())

  • data($data, $replacement = array())

  • where($where, $replacement = array())

  • leftjoin($join_string)

  • rightjoin($join_string)

  • orderby(string $orderby)

  • groupby(string $groupby)

  • having(string $having)

  • int affected_rows()

  • int insert_id()

  • query($sql, $replacement = array())

  • mixed find()

  • mixed findAll()

  • mixed findObj()

  • mixed findObjs()

  • array findPage() // 返回:array('data'=>[], 'data_count'=>0)

  • int count()

  • bool delete(bool $f)

  • int update(bool $f)

  • int insert()

  • int insert_update($update_string = '')

  • int insert_replace()

  • trans_start()

  • trans_commit()

  • trans_rollback()

  • escape_string($str)

Last updated