dongtu7205 2014-08-04 21:12
浏览 14

PDO - 需要指定bindParam或在数组工作中分配它们

I have been using the following style code:

$query = "INSERT INTO contact_messages (fromEmail, message) VALUES (:fromEmail, :message)"; 

// Create bound values
$query_params = array(  
    ':fromEmail' => $contactFrom, 
    ':message' => $contactMessage
); 

try 
{ 
    $stmt = $db->prepare($query); 
    $result = $stmt->execute($query_params); 
    $return['messageSent'] = true;
} 
catch(PDOException $ex) 
{ 
die
}

I thought that this was safe, but just seen i haven't specified that i am binding the parameters? or is what im doing still safe enough?

Also at this point, should I still be using e.g htmlPurifier on the input? or is the PDO bound parameters enough?

  • 写回答

2条回答 默认 最新

  • dougao1106 2014-08-04 21:17
    关注

    Yes it is still safe but binding parameter is safer.

    The difference is when you pass the array to execute() all the params are treated as strings.

    Whereas when you bind params you are being explicit meaning there is no way to execute with the wrong data type.

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能