经过长时间的研究,我找不到PDOException的确切解决方案SQLSTATE [HY093] 我正在使用yii 2帧工作,我在条件之间使用时遇到问题。
$query = SalesOrder::find()->where(['between','created_date', ':fromDate', ':toDate']);
$query->addParams([':fromDate' => $salesReport->fromDate,':toDate' => $salesReport->toDate]);
$query->all();
尝试了不同的同样问题。
$qString1=':fromDate';
$qString2=':toDate';
$query = SalesOrder::find()->where(['between','created_date',$qString1,$qString2]);
$query->addParams([':fromDate' => $salesReport->fromDate],[':toDate' => $salesReport->toDate]);
$query->all();
引起:PDOException SQLSTATE [HY093]:参数号无效:绑定变量数与令牌数不匹配
答案 0 :(得分:0)
在这种情况下,您无法传递参数名称。试试:
$query = SalesOrder::find()->where(['between','created_date', $salesReport->fromDate, $salesReport->toDate]);
$query->all();
或者,如果您想使用参数,请尝试:
$query = SalesOrder::find()->where('created_date BETWEEN :fromDate AND :toDate');
$query->addParams([':fromDate' => $salesReport->fromDate],[':toDate' => $salesReport->toDate]);
$query->all();