如何将多个参数绑定到 PHP 准备好的语句?

发布于 2024-08-25 18:26:17 字数 626 浏览 3 评论 0原文

"SELECT id as Id from dbTable WHERE code = ? AND CURDATE() BETWEEN 
start_date AND end_date AND offerId IN ('12321', '12124')";
//Passing arguments for the query
$args = array_merge(array(51342),$offerid);

//Execute the prepared query
$statement->execute($args);

现在数组(51342)表示代码+值的组合,除了我的数据库有值、代码列之外,所以我想要一个逻辑上看起来像这样的查询:

"SELECT id as Id from dbTable WHERE code and value 
//(Note here I do not know the syntax, 
//what am looking at is (code+value = ?), please advise on query) = ? 
AND CURDATE() BETWEEN start_date AND end_date AND offerId IN ('12321', '12124')";
"SELECT id as Id from dbTable WHERE code = ? AND CURDATE() BETWEEN 
start_date AND end_date AND offerId IN ('12321', '12124')";
//Passing arguments for the query
$args = array_merge(array(51342),$offerid);

//Execute the prepared query
$statement->execute($args);

Now array(51342) represents combination of code+value, aside my database has value, code columns and so I want a query which would look logically like:

"SELECT id as Id from dbTable WHERE code and value 
//(Note here I do not know the syntax, 
//what am looking at is (code+value = ?), please advise on query) = ? 
AND CURDATE() BETWEEN start_date AND end_date AND offerId IN ('12321', '12124')";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天煞孤星 2024-09-01 18:26:17

刚刚在搜索中找到了一个:

"SELECT id as Id from dbTable WHERE concat(code, value) = ? 
AND CURDATE() BETWEEN start_date AND end_date AND offerId IN ('12321', '12124')"

虽然不确定这是否可以正常工作!

谢谢 !!!

Just got one in the search:

"SELECT id as Id from dbTable WHERE concat(code, value) = ? 
AND CURDATE() BETWEEN start_date AND end_date AND offerId IN ('12321', '12124')"

Not sure though this would work perfectly fine !!!

Thanks !!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文