【发布时间】:2015-03-16 17:27:17
【问题描述】:
我需要运行下面的查询。它给我带来了很多麻烦。事实上,我有几个“WHERE”条件,其中一个需要分解一个数组。
This issue 帮助了我,但它没有几个条件“WHERE”。
$array = (1,2,3,4,5,6,7,8,9,10);
$clause = implode(',', array_fill(0, count($array), '?'));
if($request = $this->getConnexion()->prepare('SELECT col1, col2 FROM table WHERE col1 IN ('.$clause.') AND col2>=?') or die(mysqli_error($this->getConnexion()))) {
// The problem starts here
call_user_func_array(array($request, 'bind_param'), $array);
$request->bind_param('i', $this->getTime());
// Until here
$request->execute();
$request->bind_result($col1, $col2);
$request->store_result();
// Following the code
}
【问题讨论】:
-
您可以在使用
call_user_func_array之前将$this->getTime()添加到数组的末尾,或者使用i构建另一个array_fill,然后在bind_param中内爆 -
您的问题是什么?看起来您应该在
$clause数组中再添加一个?,而不是对bind_param()进行额外调用,并将$this->getTime()的值添加到$array值数组中,所以您只是在处理一个参数数组涵盖IN ()子句和另一个条件。 -
@Michael Berkowski,请发表你的答案,我不明白你在想什么:)
-
好的,等等——我把上面关于
$clause的部分说错了......