我需要得到今天,昨天和前天生日的人。
我正在使用yii2和postgresql,但我收到了错误
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
)
我不知道我在这段代码中做错了什么
$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();
}
答案 0 :(得分:1)
删除bind param上的单引号 像这样:
$sql = "select name from employee where date_part('day', born_date) = :dayBind and date_part('month', born_date) = :monthBind";