gpt4 book ai didi

php - Mysql 通配符和数组替换错误

转载 作者:行者123 更新时间:2023-11-29 10:34:57 25 4
gpt4 key购买 nike

我有以下数据库查询,它正在查找 MySql 表中以某种模式结尾的行。

$res = db_query('SELECT identifier FROM {rules_scheduler} WHERE identifier LIKE %:schid', array(':schid' => '_' . $sch_id));
foreach ($res as $rec) {
scheduler_delete_schedule($component, $rec->identifier);
}

但这会导致以下错误......

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%'_591'' at line 1: SELECT identifier FROM {rules_scheduler} WHERE identifier LIKE %:schid; Array ( [:schid] => _591 ) in _callback_delete_scheduled_notifications()

所以看起来我的 :schid 标记已正确替换为 _591 ,但 % 和下划线之间似乎有一个引号。我一生都无法弄清楚为什么!

最佳答案

我不知道 {rules_scheduler} 应该是什么,所以我将为您提供一个与通配符配合使用的查询字符串:

$query = "SELECT identifier FROM rules_scheduler WHERE identifier LIKE CONCAT('%', :schid)";

$res = db_query($query, [':schid' => '_' . $sch_id]);

关于php - Mysql 通配符和数组替换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46608366/

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