php - 使用查询绑定(bind) Fuelphp

标签 php mysql pdo fuelphp

当我想要 using query fuelphp binding 时遇到问题关于 IN() mysql 函数

这是我的代码

$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. 它的查询绑定(bind)不支持 mysql 的 IN() 函数?请解释
  2. 在fuelphp上还有其他方法可以查询绑定(bind)mysql的IN()函数吗?

谢谢你的回答

最佳答案

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

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

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

关于php - 使用查询绑定(bind) Fuelphp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12931989/

相关文章:

php - 扩展 PDO 类 : why does the method return 0 instead of error message?

mysql - 用pdo_mysql连接mysql,在windows运行成功,在CentOS 5.8运行失败

php - SQLSTATE[HY093] : Invalid parameter number: parameter was not defined

php - 无法在同一页面上设置 PHP cookie

javascript - PHP 表单到 JavaScript

php - Ajax 和 PHP 不更新数据库

mysql - 将整数变量传递给 MySql select 语句

php - 为什么我的 Google 标记没有显示?

javascript - jquery 数据表破坏页面上的链接

php - 客户端验证不起作用