本文整理汇总了PHP中frontend\models\User::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP User::insert方法的具体用法?PHP User::insert怎么用?PHP User::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类frontend\models\User
的用法示例。
在下文中一共展示了User::insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionAdd
public function actionAdd($password, $discuz_uid, $type = 'User')
{
//TODO 这个之后一定要写进配置文件而非硬编码
if ($password !== 'ngpt_2333') {
Yii::warning("Wrong Password!!!!!!" . $password . "uid : {$discuz_uid}");
return ['result' => 'failed', 'extra' => 'wrong password'];
}
if (is_numeric($discuz_uid) && intval($discuz_uid) <= 0) {
Yii::warning("uid not a number : {$discuz_uid}");
return ['result' => 'failed', 'extra' => 'discuz_uid should be numeric'];
}
$discuz_uid = intval($discuz_uid);
/** @var User $user */
$user = User::findOne(['discuz_user_id' => $discuz_uid]);
if (!empty($user)) {
return ['result' => 'succeed', 'extra' => $user->passkey];
}
$user = new User();
$user->discuz_user_id = $discuz_uid;
$user->passkey = User::genPasskey();
Yii::info($user->attributes);
if ($user->insert()) {
return ['result' => 'succeed', 'extra' => $user->passkey];
} else {
Yii::warning("Insert to user table failed");
return ['result' => 'failed', 'extra' => 'Database error'];
}
}
示例2: actionUser
public function actionUser()
{
User::deleteAll();
$this->fdb->createCommand('DELETE FROM ngpt_ngpt_user')->query();
//获取所有的User
$offset = 0;
$limit = 1000;
QUERY:
$sql = <<<SQL
SELECT u.*,m.adminid FROM ngpt_ngpt_users u
LEFT JOIN ngpt_common_member m ON u.uid=m.uid
LIMIT {$limit} OFFSET {$offset};
SQL;
$res = $this->fdb->createCommand($sql)->queryAll();
foreach ($res as $ouser) {
$user = new User();
$user->stat_up = $ouser['uploaded'];
$user->stat_down = $ouser['downloaded'];
$user->real_up = $ouser['realup'];
$user->real_down = $ouser['realdown'];
$user->is_valid = $ouser['candownload'] == '1';
$user->passkey = $ouser['passkey'];
$user->discuz_user_id = $ouser['uid'];
if ($ouser['adminid'] != 0) {
$user->priv = 'Admin';
}
var_dump($ouser);
if (!$user->insert()) {
var_dump($user->errors);
return;
}
//进行ngpt的数据迁移
$msql = <<<SQL
INSERT INTO ngpt_ngpt_user(uid, passkey, candownload)
VALUES ({$ouser['uid']},"{$user->passkey}", {$user->is_valid});
SQL;
$res = $this->fdb->createCommand($msql)->query();
if (!$res) {
var_dump($msql);
return;
}
}
if (count($res)) {
$offset += $limit;
goto QUERY;
}
return;
}
示例3: RegisterNewUser
public function RegisterNewUser($mobile, $password, $salt)
{
date_default_timezone_set('Asia/Shanghai');
$registerTime = date('Y-m-d H:i:s', time());
$user = new User();
$user->nickName = $mobile;
$user->password = $password;
$user->mobile = $mobile;
$user->registerTime = $registerTime;
$user->lastLoginTime = $registerTime;
$user->salt = $salt;
$user->insert();
}