douqu2712 2015-08-01 10:09
浏览 42
已采纳

使用MySQL IN()与PHP和PDO [重复]

This question already has an answer here:

I'm developing a web service and one of the parameters it takes is a list of device IDs (energy_mon_id). The list is comma separated e.g. 0,1,2 (the other two parameters it takes are dateFrom and dateTo).

My prepared statement looks like this:

$this->sql = "SELECT $vars FROM $table "

                . "WHERE energy_mon_id IN(:energy_mon_id) AND CONCAT(date, ' ', time) "
                . "BETWEEN :dateFrom AND :dateTo "
                . "$group ORDER BY $orderBy $limit";

The problem is that instead of recognising these as individual comma separated characters it's being interpreted as a complete string (I think). I tried to follow this post

I have searched around and found the exact same solution being provided (it seems to work for everyone else but me). I'm quite puzzled, never have I had to directly ask a question myself, so this is my first post!

Thanks for the help in advance.

</div>
  • 写回答

1条回答 默认 最新

  • dragon87836215 2015-08-01 15:54
    关注

    Thanks for the comments they pointed me to a suitable post with the answer. However, just to simplify for anyone that may be having a similar issue, this simple fix worked...

    instead of using:

    WHERE energy_mon_id IN(:energy_mon_id)
    

    I used:

    WHERE find_in_set(energy_mon_id, :energy_mon_id)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)