Сделать Insert where
Сделать Insert where
Привет! Подскажите, не могу сообразить. Нужно сделать unsert в таблицу user_profiles.
Я так понимаю insert используют для новых записей, для обновления update, но что если пользователя еще нет в таблице.
Я так понимаю insert используют для новых записей, для обновления update, но что если пользователя еще нет в таблице.
- vitalik1183
- Сообщения: 1675
- Зарегистрирован: 2014.07.01, 08:42
Re: Сделать Insert where
replace into
Re: Сделать Insert where
или update on duplicate
Re: Сделать Insert where
Дамп
Код: Выделить всё
modules\user\models\User Object
(
[authKey] =>
[profile] =>
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 82
[service_id] => ...
[service_url] => ...
[service] => ...
[hash_id] => u55c35ab4a61ab
[first_name] => Igor
[last_name] => Bezlepkin
[email] => ...
[password_hash] =>
[password_reset_token] =>
[auth_key] =>
[created_at] => 1438866100
[updated_at] => 1438866100
[access] => 0
[login] => 0
[role] => user
[status] => 1
[registration_ip] => ...
[data] =>
[activation_token] =>
[activated] => 1
)
[_oldAttributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 82
[service_id] => ...
[service_url] => ...
[service] => ...
[hash_id] => u55c35ab4a61ab
[first_name] => Igor
[last_name] => Bezlepkin
[email] => ...
[password_hash] =>
[password_reset_token] =>
[auth_key] =>
[created_at] => 1438866100
[updated_at] => 1438866100
[access] => 0
[login] => 0
[role] => user
[status] => 1
[registration_ip] => ...
[data] =>
[activation_token] =>
[activated] => 1
)
[_related:yii\db\BaseActiveRecord:private] => Array
(
[profile] => modules\user\models\Profile Object
(
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[user_id] => 82
[firstname] => 1232
[lastname] => ????
[uimage] => ??????
[about] =>
)
[_oldAttributes:yii\db\BaseActiveRecord:private] => Array
(
[user_id] => 82
[firstname] => 1232
[lastname] => ????
[uimage] => ??????
[about] =>
)
[_related:yii\db\BaseActiveRecord:private] => Array
(
)
[_errors:yii\base\Model:private] =>
[_validators:yii\base\Model:private] =>
[_scenario:yii\base\Model:private] => default
[_events:yii\base\Component:private] => Array
(
)
[_behaviors:yii\base\Component:private] => Array
(
)
)
)
[_errors:yii\base\Model:private] =>
[_validators:yii\base\Model:private] =>
[_scenario:yii\base\Model:private] => default
[_events:yii\base\Component:private] => Array
(
[beforeInsert] => Array
(
[0] => Array
(
[0] => Array
(
[0] => yii\behaviors\TimestampBehavior Object
(
[createdAtAttribute] => created_at
[updatedAtAttribute] => updated_at
[value] =>
[attributes] => Array
(
[beforeInsert] => Array
(
[0] => created_at
[1] => updated_at
)
[beforeUpdate] => updated_at
)
[owner] => modules\user\models\User Object
*RECURSION*
)
[1] => evaluateAttributes
)
[1] =>
)
)
[beforeUpdate] => Array
(
[0] => Array
(
[0] => Array
(
[0] => yii\behaviors\TimestampBehavior Object
(
[createdAtAttribute] => created_at
[updatedAtAttribute] => updated_at
[value] =>
[attributes] => Array
(
[beforeInsert] => Array
(
[0] => created_at
[1] => updated_at
)
[beforeUpdate] => updated_at
)
[owner] => modules\user\models\User Object
*RECURSION*
)
[1] => evaluateAttributes
)
[1] =>
)
)
)
[_behaviors:yii\base\Component:private] => Array
(
[0] => yii\behaviors\TimestampBehavior Object
(
[createdAtAttribute] => created_at
[updatedAtAttribute] => updated_at
[value] =>
[attributes] => Array
(
[beforeInsert] => Array
(
[0] => created_at
[1] => updated_at
)
[beforeUpdate] => updated_at
)
[owner] => modules\user\models\User Object
*RECURSION*
)
)
)
Re: Сделать Insert where
в index.php выключи php warnings, и все будет гуд
Re: Сделать Insert where
Значит делаешь select, который возвращает false, и в том случае делаешь insert.
Это наиболее бескостыльный вариант. Т.к. нативного update on duplicate - в yii нет (по причине что субд-зависимая вещь)
Его первое сообщение. Хотел показаться умным