gpt4 book ai didi

php - DBO 选择等于和喜欢的地方

转载 作者:行者123 更新时间:2023-11-30 22:16:23 24 4
gpt4 key购买 nike

我已经尝试用以下 100 种不同的方式编写代码,但无法找出正确的语法。看来无论我怎么写, $loggeduser 都不会传递给 WHERE 用户名。我究竟做错了什么?什么是正确的语法?

$query = $db->prepare('SELECT * FROM sites WHERE username = ? AND name LIKE ? OR login LIKE ? AND category="te"');
$query->bindValue(1, $loggeduser);
$query->bindValue(2, '%'.$_POST[search].'%');
$query->bindValue(3, '%'.$_POST[search].'%');
$query->execute();}

最佳答案

根据 this comment

When binding parameters, apparently you can't use a placeholder twice (e.g. "select * from mails where sender=:me or recipient=:me"), you'll have to give them different names otherwise your query will return empty handed (but not fail, unfortunately).

这可能是您的问题,因为您正试图将相同的值绑定(bind)到两个单独的占位符。请尝试以下操作:

$query = $db->prepare('SELECT * FROM sites WHERE username = :username AND name LIKE :name OR login LIKE :login AND category="te"');
$query->bindValue(:username, $loggeduser);
$query->bindValue(:name, '%'.$_POST['search'].'%');
$query->bindValue(:login, '%'.$_POST['search'].'%');
$query->execute();

关于php - DBO 选择等于和喜欢的地方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38153786/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com