动态绑定举例
OM books';
if($title !==''){//添加title查询条件(LIKE)
$conditions[] = "title LIKE ? ESCAPE '#'";
$ph_type[] ='text';
$ph_value[]= esape_wildcard($title);
}
if($price !== ''){//添加price上限查询条件
$conditions[] = "price <= ?";
$ph_type[] ='integer';
$ph_value[]= $price;
}
if(count($conditions) > 0){//存在where语句时
$sql .= ' WHERE '.implode(' AND ',$conditions);
}
$stmt = $mdb2 ->prepare($sql , $ph_type);//准备SQL语句
$rs = $stmt->excute($ph_value);//执行变量绑定和查询
?>








