我的查询工作正常。当我将其更改为pdo时,我收到语法错误。
这是我的代码:
if(isset($_GET['detail'])){
$kosul = " and :puan_x and :e_a_k_v and :kimden_v and :para_birimi_v and :fiyat_q and :tarih_x and :ilce_id and :mahkoy_id";
}
$query="SELECT :distance t0.idsx, t1.knt_f_ilce_id, t1.knt_f_mahkoy_id, t1.ilce, t1.mahalle, t1.lat, t1.lng, t2.page_title, t2.page_url, t0.uniq_key,
t5.fiyat_salt, t5.m0, t4.e_durumu, t4.e_kat, t4.e_alt_kat, t5.fiyat_para_birimi, to_char(t1.i_tarihi, 'DD-MM-YYYY')::character varying(10) AS i_tarihi,
t4.e_durumu_int, t4.e_kat_int, t4.e_alt_kat_int, t7.oda_sayisi, t3.iletisim_id, t0.kaynak, left(t2.aciklama,150) || '...' as aciklamax, t2.resim, t2.kimden, t6.max_puan_yuzde
FROM pbl.i_lokasyon t1
join pbl.i_detay_x t2 on t1.idsx = t2.idsx
join pbl.i_index t0 on t1.idsx = t0.idsx
join pbl.i_iletisim t3 on t1.idsx = t3.idsx
join pbl.i_durum t4 on t1.idsx = t4.idsx
join pbl.i_m0 t5 on t1.idsx = t5.idsx
join pbl.i_puan t6 on t1.idsx = t6.idsx
join pbl.i_bina t7 on t1.idsx = t7.idsx
:geom and t4.e_durumu is not null and
t4.e_kat is not null
and :e_durumu_v and :e_kat_v and :kaynak_v $kosul order by :sort limit 100 offset :offset";
$params = array("distance"=>$distance, "geom"=>$geom, "e_durumu_v"=>$e_durumu_v, "e_kat_v"=>$e_kat_v, "kaynak_v"=>$kaynak_v, "sort"=>$sort, "offset"=>$offset);
if (isset($_GET['detail'])){
$params["puan_x"] = $puan_x;
$params["e_a_k_v"] = $e_a_k_v;
$params["kimden_v"] = $kimden_v;
$params["para_birimi_v"] = $para_birimi_v;
$params["fiyat_q"] = $fiyat_q;
$params["tarih_x"] = $tarih_x;
$params["ilce_id"] = $ilce_id;
$params["mahkoy_id"] = $mahkoy_id;
}
$data = Database::query($query, $params);
当我打印$ data时,它给了我这个错误:
array(3) {
[0]=>
string(5) "42601"
[1]=>
int(7)
[2]=>
string(129) "ERROR: syntax error at or near "."
LINE 1: SELECT $1 t0.id_seq_x, t1.knt_f_ilce_id, t1.knt_f_mahkoy_id,...
^"
}
这是我的变量:
var_dump($distance) = string(0) ""
var_dump($geom) = string(22) "where geom is not null"
var_dump($emlak_durumu_v) = string(27) " t4.emlak_durumu_int = 2 "
var_dump($emlak_kategori_v) = string(29) " t4.emlak_kategori_int = 1 "
var_dump($kaynak_v) = string(21) " t0.kaynak_int = 1 "
var_dump($sort) = string(16) "t0.id_seq_x desc"
var_dump($offset) = string(1) "0"
var_dump($kosul) = NULL
当我在sql窗格中运行此查询时,它工作正常,记录来了。我的问题在这段代码中有什么问题。谢谢你的回答。