开发者

Should I be binding individual array entries, or just executing the array with PDO

I have an assoc array filled with the values necessary for a PDOstatement. Should I, bind each value开发者_如何转开发 then call execute? Or call execute passing it the array of values?

Array(
  [name] => Joe
  [value] => some content
)

Should I:

foreach($data as $key => $value){
  $statement->bindValue($key, $value);
}
execute();

OR

execute($data);

As far as I am aware, binding the data does some form of data sanitation similar to mysql_real_escape_string. I am uncertain whether I need to bind the values to achieve that affect or if I can just pass the data array to execute() and assume it has been properly escaped?


As far as you do a prepare(), you can bind values in any way you want.

Read the docs; link text link text


It doesn't matter when you use a prepared statement.

Please note that your data will not be sanitized nor escaped in any way, it is entered in the database exactly as it is.

By the way, Kemo is right, but this is the more appropriate link: or use bind or use an array

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜