简体   繁体   English

Yii createCommand使用bindValue更新

[英]Yii createCommand Update with bindValue

I'm using createCommand in Yii Framework and I want to know about use bindValue for the params, Ex: 我在Yii Framework中使用createCommand,并且想了解有关对参数使用bindValue的信息,例如:

Yii::app()->db->createCommand()
                            ->update('table', array(
                            'field'=>'$valuefield',
                            ), 'id_table=:id_table', array(':id_table'=>$id_table));

In this case, the value of $valuefield and $id_table are protected? 在这种情况下,$ valuefield和$ id_table的值是否受到保护? Or I should create the sql query manually and pass the parameters with bindValue? 还是我应该手动创建sql查询并通过bindValue传递参数?

Thank you! 谢谢!

In this case, the value of $valuefield and $id_table are protected? 在这种情况下,$ valuefield和$ id_table的值是否受到保护?

Yes. 是。 Method update automaticly binds array's values passed in second param. 方法update自动绑定在第二个参数中传递的数组的值。 And also you manualy bind param for condition. 而且,您还可以手动绑定参数来满足条件。 To prevent SQL injection always use binding. 为了防止SQL注入,请始终使用绑定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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