Created
June 8, 2024 12:41
-
-
Save susilolab/fffa1c35dc0933a24954376ebddd3d74 to your computer and use it in GitHub Desktop.
Secure delete dan update pada yii1 dengan CDbCommand
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
// delete data tabel user yang id nya 1,2,3 | |
Yii::app()->db->createCommand()->delete('user', ['in', 'user_id', [1, 2, 3]); | |
// update posts set published 1 yang id postnya 1,2,3 | |
Yii::app()->db->createCommand()->update('posts', ['published' => 1], ['in', 'id', [1, 2, 3]); | |
// query where tidak bisa menggunakan array seperti diatas, harus pakai string kondisi dan array params | |
Yii::app()->db->createCommand()->select('id, name')->from('user')->where('id = :id', [':id' => 1])->queryRow(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment