本文整理匯總了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();
}