如果参数中有空格,则将参数传递给 sql 查询时出现问题。代码是
$statement="select di_timestamp, di_item_value
from data_item
where
fk_fc_id=(select fc_id
from field_column
where
fc_description ilike :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'=>$sensor,':room'=>$room,':name' => '%'.$school.'%'));
但是,如果传感器包含任何空格,则查询失败。我该如何解决这个问题?我试过在参数中加上引号,在查询中加上引号,但没有任何效果。