Reputation: 412
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();
}
Upvotes: 0
Views: 357
Reputation: 3771
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";
Upvotes: 1