简体   繁体   中英

Save safe string with createMultipleInsertCommand in yii project

How can i create safe string in yii, if i want to save multiple data? This is my code:

$builder = Yii::app()->db->schema->commandBuilder;
$command = $builder->createMultipleInsertCommand('ewl_team_user', array(
    array('user_name'=>'record1', 'user_desc'=>'leírás','team_id'=>1),
    array('user_name'=>'record2', 'user_desc'=>'leírás','team_id'=>1),
    array('user_name'=>'record3', 'user_desc'=>'leírás','team_id'=>1),
));

How can i use PDO params in this code? Where should i write this part?

'params'=>array(':t'=>$data)

As I said in the comments, CDbCommandBuilder#createMultipleInsertCommand does not have any params argument. So the better way is to use CActiveRecord for saving data. First, you need to generate Model from table entity by Gii tools. If you are not familiar with Gii, refer this link . Then you can instantiate any number of objects, assign desired values to attributes, and finally save them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM