我新来的PHP PDO,我想通过参数去查询在准备发言,但我已经失败了一次又一次,虽然这是工作中的mysqli报表不错,但在这里它没有显示我的记录没有显示任何error..problem是与经过PARAMS请有人指导我...
这里是我的代码..
if($_GET['title']!="" && isset($_GET['cities']) && isset($_GET['categories'])){
$title = trim($_GET['title']);
$cities = $_GET['cities'];
$categories = $_GET['categories'];
foreach($cities as $city) {
$recordcities .= $city."|";
}
foreach($categories as $category){
$recordCat .= $category."|";
}
$select = $pdo->prepare("select * from selectcities WHERE CONCAT(',', `cities`, ',') REGEXP ',(:cities),' and CONCAT(',', `category`, ',') REGEXP ',(:categories),' ");
$select->bindParam(':cities',$recordCities,PDO::PARAM_STR);
$select->bindParam(':categories',$recordCat,PDO::PARAM_STR);
$select->execute();
echo $select->rowCount();
while($result = $select->fetch(PDO::FETCH_ASSOC)){
//echo $result['Title'].'<br>';
print_r($result);
}
}
我认为你必须使绑定变量包含任何额外的标记,而不是试图将其包含在SQL,所以你的绑定成为',('.$recordCities.'),'
和SQL只是REGEXP :cities
...
$select = $pdo->prepare("select * from selectcities
WHERE CONCAT(',', `cities`, ',') REGEXP :cities
and CONCAT(',', `category`, ',') REGEXP :categories ");
$recordCities = ',('.$recordCities.'),';
$recordCat = ',('.$recordCat.'),';
$select->bindParam(':cities',$recordCities,PDO::PARAM_STR);
$select->bindParam(':categories',$recordCat,PDO::PARAM_STR);