doukang1962 2015-01-09 19:15
浏览 78
已采纳

准备好的陈述 - 我是否应该在没有(?)占位符的查询中使用php预处理语句?

It makes perfect sense to me to use prepared statements in a query of the following type:

$sqlQuery = "SELECT phone FROM contact WHERE name = ? ";

However, in the following situation, does it make sense and is it useful to use prepared statements, as sometimes seen?

$sqlQuery = "SELECT name FROM contact";

Thanks in advance

  • 写回答

2条回答 默认 最新

  • duanfu1942 2015-01-09 19:32
    关注

    If you are running a query without any user-entered variables, you can just do:

    $db->query("SELECT name FROM contact")
    

    As soon as you start entering in user-inputted data, then you need to use a prepared statement.

    $db->prepare("SELECT phone FROM contact WHERE name = ?");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 定制ai直播实时换脸软件
  • ¥100 栈回溯相关,模块加载后KiExceptionDispatch无法正常回溯了
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错
  • ¥15 java python或者任何一种编程语言复刻一个网页
  • ¥20 如何通过代码传输视频到亚马逊平台
  • ¥15 php查询mysql数据库并显示至下拉列表中