gpt4 book ai didi

php - MYSQL IN 子句错误

转载 作者:行者123 更新时间:2023-11-30 01:21:56 25 4
gpt4 key购买 nike

我在mysql查询中使用了以下代码:

$all_PIDs=array();
foreach($pID as $p)
{
$all_PIDs[]=$p->ID;
}
$AIDS=implode(',',$all_PIDs);
$table_tsk = new Timesheets_Table_Tasks();
$select_tsk = $table_tsk->select()
->from($table_tsk, array
(
'Total'=>'SUM(timesheets_tasks.Time)',
'Charged'=>'SUM(timesheets_tasks.Time_Charged)'
))
->where('timesheets_tasks.ProjectID IN ('.$AIDS.')')
;

但是使用上面的代码我收到以下错误:

"An error has occured 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 '))' at line 1"

我为 IN 子句添加了引号(")。但问题是查询仅显示第一个 $AIDS有人可以帮我清除错误吗?谢谢!

最佳答案

应指定为:

->where('timesheets_tasks.ProjectID IN (?)', $all_PIDs)

因此您传递的是整数数组,而不是逗号分隔的列表

关于php - MYSQL IN 子句错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18434822/

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