連接到數據庫時出現此問題。我正在嘗試編寫一個包含子查詢的查詢,以在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'而不是'='也是這麼多的子查詢會殺死你的分區 –