【问题标题】:Using Query Binding Fuelphp使用查询绑定 Fuelphp
【发布时间】:2012-10-17 10:11:16
【问题描述】:

当我想在IN() mysql 函数上using query fuelphp binding 时遇到问题

这是我的代码

$status_array = array(1,2,3);
$query = 'select * from users where status IN(:status_id_as_array)' ;
$user = DB::query($query)->bind('status_id_as_array',$status_array)->execute();

当我使用

进行调试时,该代码的结果为零
echo DB::last_query();

最后一个查询是

select * from users where status IN('1,2,3');

我认为问题是IN('1,2,3') IN 的值是字符串,所以它不能作为数组模式执行。

请注意,我可以用另一种方式实现目标

 $query = 'select * from users where status IN('.implode(',', $status_array).')' ;

我的问题是

  1. 查询绑定不支持mysql的IN()函数?请解释
  2. 在fuelphp上,还有另一种查询绑定mysql的IN()函数的方法吗?

感谢您的回答

【问题讨论】:

    标签: php mysql pdo fuelphp


    【解决方案1】:

    还有另一种方法可以处理您的查询。试试:

    $user = DB::select()->from('users')
        ->where('status', 'in', $status_array)
        ->execute();
    

    它将执行如下查询:SELECT * FROM `users` WHERE `status` IN (1, 2, 3)

    【讨论】:

    • 在其他情况下,我看不到如何执行它.. 除了你的“其他方式”
    猜你喜欢
    • 2015-01-10
    • 1970-01-01
    • 1970-01-01
    • 2015-02-26
    • 2021-03-14
    • 1970-01-01
    • 2017-11-30
    • 2022-01-09
    • 2017-10-23
    相关资源
    最近更新 更多