本文整理匯總了PHP中think\Model::master方法的典型用法代碼示例。如果您正苦於以下問題:PHP Model::master方法的具體用法?PHP Model::master怎麽用?PHP Model::master使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類think\Model
的用法示例。
在下文中一共展示了Model::master方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testQuery
public function testQuery()
{
$user_model = new Model('user', $this->getConfig());
$sql = "select id,create_time from tp_user where username='test' limit 1";
$result = $user_model->query($sql);
$id = $result[0]['id'];
$time = $result[0]['create_time'];
$bind = ['create_time' => $time, 'status' => 1];
$info = $user_model->where(['create_time' => ':create_time'])->where(['status' => ':status'])->bind($bind)->field(true)->find(['cache' => ['key' => true]]);
$data = ['id' => $id, 'username' => 'test', 'password' => md5('123456'), 'status' => '1', 'create_time' => $time];
$this->assertEquals($data, $info);
$_GET['id'] = $id;
$result = $user_model->where(['id' => ':id'])->bind('id', $_GET['id'])->field('password,create_time', true)->order('id')->limit('0,10')->select(['cache' => ['key' => true, 'expire' => 0], 'index' => 'username']);
$data = ['id' => $id, 'username' => 'test', 'status' => '1'];
$this->assertEquals($data, $result['test']);
$_GET['status'] = '1';
$result = $user_model->where(['status' => ':status'])->bind('status', $_GET['status'], \PDO::PARAM_INT)->field('password,create_time', true)->order('id', 'desc')->index('id,username')->page('0,10')->select();
$data = ['1' => 'test', '2' => 'test2'];
$this->assertEquals($data, $result);
$time = $user_model->where(['status' => 1])->cache('user_create_time')->getField('create_time');
$ids = $user_model->where(['status' => 1])->cache('user_id')->getField('id', true);
$this->assertEquals(2, count($ids));
$result = $user_model->cache(true)->getField('username,status,create_time', '|');
$data = ['test' => '1|' . $time, 'test2' => '1|' . $time];
$this->assertEquals($data, $result);
$result = $user_model->cache(10)->getField('username,status');
$data = ['test' => '1', 'test2' => '1'];
$this->assertEquals($data, $result);
$result = $user_model->scope(['field' => 'username', 'where' => 'status=1'])->select();
$data = [['username' => 'test'], ['username' => 'test2']];
$this->assertEquals($data, $result);
$result = $user_model->master()->lock(true)->distinct(true)->force('create_time')->comment('查詢用戶名')->field('username')->fetchSql(true)->select();
$sql = 'SELECT DISTINCT `username` FROM `tp_user` FORCE INDEX ( create_time ) FOR UPDATE /* 查詢用戶名 */';
$this->assertEquals($sql, $result);
$order_model = new Model('order', $this->getConfig());
$result = $order_model->field('user_id,sum(amount) amount')->group('user_id')->having('sum(amount) > 1000')->select();
$this->assertEmpty($result);
$result = $order_model->getLastSql();
$sql = 'SELECT `user_id`,sum(amount) amount FROM `tp_order` GROUP BY user_id HAVING sum(amount) > 1000 ';
$this->assertEquals($sql, $result);
}