WHERE 子句与 PDO 混淆 [英] WHERE clause confusion with PDO

查看:36
本文介绍了WHERE 子句与 PDO 混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您需要一次将一个值与多个列进行匹配时,我无法理解如何使用准备好的语句.

I'm having some trouble understanding how to use prepared statements, when you need to match one value against several columns at once.

换句话说,不是这样做:

In other words what instead of doing this:

$stmt = $dbh->prepare("SELECT * FROM REGISTRY where name = ?");
$stmt->bindParam(1, $name); 

我想这样做:

$stmt = $dbh->prepare("SELECT * FROM REGISTRY where firstname = ? or lastname = ?");

同时带有?"表示相同的字符串.

with both '?' representing the same string.

推荐答案

尝试...

$stmt = $dbh->prepare("SELECT * FROM registry WHERE firstname = :name OR lastname = :name;");
$stmt->bindParam(':name', $name); 

这篇关于WHERE 子句与 PDO 混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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