dq_1984 2015-08-21 19:19
浏览 58
已采纳

Yii2 - HY093中的查询错误

I need to get people who has birthday today, yesterday and the day before yesterday.

I'm using yii2 and postgresql, but I'm getting the error

SQLSTATE[HY093]: Invalid parameter number: :dayBind
Failed to prepare SQL: select name from employee
where date_part('day', born_date) = ':dayBind' and date_part('month', born_date) = ':monthBind'
Error Info: Array
(
    [0] => HY093
    [1] => 0
)

I don't know what I'm doing wrong in this code

 $days = array('day before yesterday' => date('m/d',  strtotime("-2 days"))
             , 'yesterday' => date('m/d',  strtotime("-1 days"))
             , 'today' => date('m/d')
 );

 $sql = "select name from employee
            where date_part('day', born_date) = ':dayBind' and date_part('month', born_date) = ':monthBind'";

 $result = array();
 foreach($days as $definition => $date) {

        list($m, $d) = explode("/", $date);

        $params = array(':dayBind' => $d, ':monthBind' => $m);

        $result[$definition] = Yii::$app->db->createCommand($sql)->bindValues($params)->queryAll();
 }
  • 写回答

1条回答 默认 最新

  • dpziir0079 2015-08-24 02:18
    关注

    Remove single quote marks on bind param.
    Like this :

    $sql = "select name from employee where date_part('day', born_date) = :dayBind and date_part('month', born_date) = :monthBind";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试