本文整理汇总了PHP中think\Model::db方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::db方法的具体用法?PHP Model::db怎么用?PHP Model::db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类think\Model
的用法示例。
在下文中一共展示了Model::db方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sql
private function sql()
{
//迁移数据
//初始化Model
$connection_new = array('DB_TYPE' => 'mysql', 'DB_HOST' => 'localhost', 'DB_NAME' => 'web_association', 'DB_USER' => 'root', 'DB_PWD' => '', 'DB_PORT' => 3306, 'DB_PREFIX' => 'wa_', 'db_charset' => 'utf8');
$connection_old = array('DB_TYPE' => 'mysql', 'DB_HOST' => 'localhost', 'DB_NAME' => 'association', 'DB_USER' => 'root', 'DB_PWD' => '', 'DB_PORT' => 3306, 'DB_PREFIX' => '', 'db_charset' => 'utf8');
$new_mo = new Model();
$new_mo->db(null, $connection_new);
$old_mo = new Model();
$old_mo->db(null, $connection_old);
/*/数据迁移userinf_login
$old_mo->table('userinf_login');
$all_user=$old_mo->select();
$abc_time=array(
'A'=>'2014-12-10 23:33:33',
'B'=>'2015-03-30 23:33:33',
'C'=>'2015-09-01 23:33:33',
);
$data=array();
for ($i = 0; $i < count($all_user); $i++) {
//赋值users表
preg_match('/^\w/', $all_user[$i]['id_formal'],$reStr);
$data['uid'] =$all_user[$i]['id_formal'];
$data['qq'] =$all_user[$i]['id_person'];
$data['password'] =$all_user[$i]['password'];
$data['date'] =$abc_time[$reStr[0]];
$new_mo->table('__USERS__');
$new_mo->add($data,null,true);
//赋值token表
$new_mo->table('__TOKEN__');
$new_mo->add(array('uid'=>$all_user[$i]['id_formal'],'token'=>get_rand_char(20)),null,true);
}
//数据迁移userinf_basic
$old_mo->table('userinf_basic');
$all_basic=$old_mo->select();
for ($i = 0; $i < count($all_basic); $i++) {
//填充__USER_INF__
$data1=array();
$data1['uid'] = $all_basic[$i]['id_formal'];
$data1['name'] = $all_basic[$i]['name'];
$data1['gender'] = $all_basic[$i]['sex'];
$data1['age'] = $all_basic[$i]['old'];
$data1['phone'] = $all_basic[$i]['phone'];
$data1['school'] = $all_basic[$i]['school'];
$data1['wechat'] = $all_basic[$i]['wechat'];
$new_mo->table('__USER_INF__')->add($data1,null,true);
//填充__NUTS__
$data2=array();
$data2['uid'] = $all_basic[$i]['id_formal'];
$data2['cumulative'] = $all_basic[$i]['integral_cumulative'];
$data2['nuts'] = $all_basic[$i]['integral_surplus'];
$new_mo->table('__NUTS__')->add($data2,null,true);
};
//数据迁移userinf_active
$old_mo->table('userinf_active');
$all_active=$old_mo->select();
for ($i = 0; $i < count($all_active); $i++) {
//填充__INVITE_CODE__
$new_mo->table('__INVITE_CODE__');
$data['invite_code'] =$all_active[$i]['active'];
$data['date'] =$all_active[$i]['date'];
$data['uid'] =$all_active[$i]['user'];
$new_mo->add($data);
}
//更新时间
$userMo=new UsersModel();
$codeMo=new InviteCodeModel();
$allUser=$userMo->field('date,uid')->select();
var_dump($allUser);
for ($i=0;$i<\count($allUser);$i++){
$codeMo->where(array('uid'=>$allUser[$i]['uid']));
$codeMo->data(array('date'=>$allUser[$i]['date']));
$userMo->save();
}
//*/
}
示例2: testDelete
public function testDelete()
{
$config = $this->getConfig();
$order_model = new Model('order', $config);
$order_model->id = 2;
$flag = $order_model->delete();
$this->assertEquals(1, $flag);
$flag = $order_model->delete('1');
$this->assertEquals(1, $flag);
$address_model = new Model('user_address', $config);
$flag = $address_model->delete(['1', '2']);
$this->assertEquals(2, $flag);
$user_model = new Model('user', $config);
$flag = $user_model->using([''])->where('1=1')->delete();
$this->assertEquals(2, $flag);
$ru_model = new Model('role_user', $config);
$flag = $ru_model->delete(['1', '1']);
$this->assertEquals(1, $flag);
$sql = <<<EOF
DROP TABLE IF EXISTS `tp_user`;
DROP TABLE IF EXISTS `tp_order`;
DROP TABLE IF EXISTS `tp_user_address`;
DROP TABLE IF EXISTS `tp_role_user`;
EOF;
$model = new Model('', $this->getConfig());
$model->execute($sql);
$flag = $model->db(0, null);
$this->assertNull($flag);
}