我不知道我的代码是什么意思...你使用mysqli,当我执行时他会显示这个错误,有一个凸轮可以帮助我吗?
$mysqli = new mysqli($db_host, $db_username, $db_password, $db_name);
if ($mysqli->connect_error) {
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
$results = $mysqli->prepare("SELECT * FROM `imovel` WHERE `finalidade` LIKE $finalidade AND `nquartos` = $nquarto AND `tipoimovel` LIKE $tipoimovel AND `preco` BETWEEN $pmin AND $pmax AND `conselho` LIKE $conselho AND `frequesia` LIKE $frequesia AND `referencia` = $refimovel AND `garagem` = $garagem AND `jardim` = $jardim AND `piscina` = $piscina AND `condominio` = $condominiof AND `elevador` = $elevador AND `vistapreveligiada` = $vistapriv ORDER BY `imovel`.`preco` DESC LIMIT $page_position, $item_per_page");
$results->execute(); //Execute prepared Query
$results->bind_result($id ,$imagem, $frequesia ,$conselho, $preco); //bind variables to prepared statement
答案 0 :(得分:1)
这应该更接近你准备好的准备陈述。使用当前执行时,SQL无效。
$mysqli = new mysqli($db_host, $db_username, $db_password, $db_name);
if ($mysqli->connect_error) {
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
$results = $mysqli->prepare("SELECT * FROM `imovel` WHERE `finalidade` LIKE ? AND `nquartos` = ? AND `tipoimovel` LIKE ? AND `preco` BETWEEN ? AND ? AND `conselho` LIKE ? AND `frequesia` LIKE ? AND `referencia` = ? AND `garagem` = ? AND `jardim` = ? AND `piscina` = ? AND `condominio` = ? AND `elevador` = ? AND `vistapreveligiada` = ? ORDER BY `imovel`.`preco` DESC LIMIT ?, ?");
$results->bind_param("sssiisssssssssii", $finalidade, $nquarto, $tipoimovel, $pmin, $pmax, $conselho, $frequesia, $refimovel, $garagem, $jardim, $piscina, $condominiof, $elevador, $vistapriv, $page_position, $item_per_page);
$results->execute(); //Execute prepared Query
$results->bind_result($id ,$imagem, $frequesia ,$conselho, $preco); //bind variables to prepared statement
SQL中的字符串需要引用,或者用占位符替换(这是?
的内容)。使用占位符,驱动程序将替换值并处理引用。
这个查询也有很多要求我希望你在使用之前在你的数据库上运行它,因为它可能没有任何结果返回...