PDO Postgres 无效错误


PDO Postgres Invalid error

我在连接到数据库时遇到此问题。我正在尝试编写一个包含子查询的查询,以便在 Postgres(使用PDO)上运行。不幸的是,我收到"无效的参数编号::传感器"

    $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 中导致错误。

感谢您查看此内容,詹姆斯

尝试删除参数名称两边的单引号,如下所示:

从 => ':sensor' 到 => :sensor

在此链接中,您将找到解释。