当前位置: 首页>>代码示例>>PHP>>正文


PHP Model::master方法代码示例

本文整理汇总了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);
 }
开发者ID:cnzin,项目名称:think,代码行数:41,代码来源:modelTest.php


注:本文中的think\Model::master方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。