连接到数据库时出现此问题。我正在尝试编写一个包含子查询的查询,以在Postgres,usind PDO上运行。不幸的是,我得到一个“无效参数号:传感器”PDO Postgres无效的错误
$statement="select di_timestamp, di_item_value
from data_item
where
fk_fc_id=(select fc_id
from field_column
where
fc_description is like ':sensor'
and
fk_mds_id=(select mds_id
from monitored_data_set
where fk_pa_id=(select pa_id
from pilot_ambient
where
pa_ambient_name ilike ':room'
and
fk_sp_id=(
select sp_id
from School_Pilot
where sp_description ilike '%:name%'
)
)
)
)";
$query = $databaseConn->prepare($statement);
$query->execute(array(':sensor'=>'Room Temperature',':room'=>'rm1',':name' => 'school1'));
我想我的问题是,因围绕的'字符转义:(项目)。我尝试过使用\,但那会产生一个语法错误。我认为有一个约定我不知道PHP成功替换字符串,然后它不会导致Postgres中的错误。
感谢您看这个, 詹姆斯
使用'in'而不是'='也是这么多的子查询会杀死你的分区 –