[英]PHP PDO Check if row exist with two WHERE Condition
I'm trying to look for the text exist in the row inside the table called website.我正在尝试查找名为 website 的表内的行中存在的文本。
Where uid
is INT and domain
is String.其中
uid
是 INT, domain
是 String。
If the Row is found and both uid
and domain
matches.如果找到 Row 并且
uid
和domain
都匹配。 It should output success
.它应该 output
success
。
If the Row Value doesn't exist, it should output nothing
如果行值不存在,它应该 output
nothing
Both UID
and domain
are giving by the user in input form. UID
和domain
都是由用户以输入形式提供的。
With the below code, It's not working.使用以下代码,它不起作用。 I'm not sure what I'm doing wrong.
我不确定我做错了什么。
$stmt = $conn->prepare('SELECT * FROM website WHERE uid=:uid AND domain=:domain');
$stmt->bindParam(1, $_GET['uid'], PDO::PARAM_INT);
$stmt->bindParam(2, $_GET['domain'], PDO::PARAM_STR);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if($row)
{
echo "found";
}
else {
echo "nothing";
}
With bindParam()
, the first parameter is the bind point.使用
bindParam()
,第一个参数是绑定点。 From the manual从手册
Parameter identifier.
参数标识符。 For a prepared statement using named placeholders, this will be a parameter name of the form:name .
对于使用命名占位符的准备好的语句,这将是形式的参数名称:名称。 For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter.
对于使用问号占位符的准备好的语句,这将是参数的 1 索引 position。 (emphasis mine).
(强调我的)。
As you use named parameters in your SQL, you should use...当您在 SQL 中使用命名参数时,您应该使用...
$stmt->bindParam('uid', $_GET['uid'], PDO::PARAM_INT);
etc.等等
(Not sure if there is a duplicate for this, will remove if one is found). (不确定是否有重复,如果找到将删除)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.