嗨,我正在使用 Agile Toolkit 编写一些 DSQL 查询,但有点困惑。给定以下 DSQL 代码:
$select = $select->add('Model_Rental')->dsql()
->field('id')
->where('dvd_id', $select->getField('id'))
->where('is_returned!=', 'Y');
return "if(($select) is null,'N','Y')";
我收到以下 SQL 错误:
pdo_error: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound
mode: select
params: Array ( )
query: select (select `name` from `movie` where `dvd`.`movie_id` = `movie`.`id` ) `movie`,`code`,if((select `id` from `rental` where `dvd_id` = `dvd`.`id` and `is_returned` != :a ) is null,'N','Y') `is_rented`,`id` from `dvd`
template: select [options] [field] [from] [table] [join] [where] [group] [having] [order] [limit]
但是当我在同一个引号内定义条件时,我没有收到错误:
$select = $select->add('Model_Rental')->dsql()
->field('id')
->where('dvd_id', $select->getField('id'))
->where('is_returned!="Y"');
return "if(($select) is null,'N','Y')";
这给了我预期的:
select (select `name` from `movie` where `dvd`.`movie_id` = `movie`.`id` ) `movie`,`code`,if((select `id` from `rental` where `dvd_id` = `dvd`.`id` and is_returned!="Y" ) is null,'N','Y') `is_rented`,`id` from `dvd`
为什么我必须将状态写为:
->where('is_returned!="Y"');
为什么我不能像往常一样写:
->where('is_returned!=', 'Y');
谢谢!