doumu9019 2014-01-14 09:49
浏览 27
已采纳

使用PDO而不绑定

$stmt = $conn->prepare('SELECT * FROM users WHERE user_id = :user_id');

$stmt->execute(array(':user_id' => $_GET['user_id']));

$result = $stmt->fetchAll(PDO::FETCH_OBJ);

I'm using PDO like that, do I need to sanitise GET parameter?

I know if I do $stmt->bindParam(':user_id', $_GET['user_id'], PDO::PARAM_INT); than it is not a problem. But is my way safe?

  • 写回答

1条回答 默认 最新

  • dtyqeoc70733 2014-01-14 09:51
    关注

    Yes, it's safe. The only differences between execute and bind* are:

    • execute accepts several parameters at once, while you have to bind* each one individually
    • bind* allows you to specify the parameter type, while execute binds everything as strings

    Passing parameters to execute is mostly a convenience shorthand, it's still safe.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 数字取证课程 关于FAT文件系统的操作
  • ¥15 如何使用js实现打印时每页设置统一的标题
  • ¥15 安装TIA PortalV15.1报错
  • ¥15 能把水桶搬到饮水机的机械设计
  • ¥15 Android Studio中如何把H5逻辑放在Assets 文件夹中以实现将h5代码打包为apk
  • ¥15 使用小程序wx.createWebAudioContext()开发节拍器
  • ¥15 关于#爬虫#的问题:请问HMDB代谢物爬虫的那个工具可以提供一下吗
  • ¥15 vue3+electron打包获取本地视频属性,文件夹里面有ffprobe.exe 文件还会报错这是什么原因呢?
  • ¥20 用51单片机控制急停。
  • ¥15 孟德尔随机化结果不一致