Yii createCommand 使用 bindValue 更新 [英] Yii createCommand Update with bindValue

查看:26
本文介绍了Yii createCommand 使用 bindValue 更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Yii 框架中使用 createCommand,我想知道使用 bindValue 作为参数,例如:

I'm using createCommand in Yii Framework and I want to know about use bindValue for the params, Ex:

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

在这种情况下,$valuefield 和 $id_table 的值是否受到保护?或者我应该手动创建 sql 查询并使用 bindValue 传递参数?

In this case, the value of $valuefield and $id_table are protected? Or I should create the sql query manually and pass the parameters with bindValue?

谢谢!

推荐答案

在这种情况下,$valuefield 和 $id_table 的值是否受到保护?

In this case, the value of $valuefield and $id_table are protected?

是的.方法 update 自动绑定传入第二个参数的数组值.并且您还手动绑定条件参数.为了防止 SQL 注入,请始终使用绑定.

Yes. Method update automaticly binds array's values passed in second param. And also you manualy bind param for condition. To prevent SQL injection always use binding.

这篇关于Yii createCommand 使用 bindValue 更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆