Dynamic Sql and PDO's bindParam. How to get this to work?
In my script, I generate sql based on what comes in from the url and thru
htaccess
So, Http://www.domain.com/us/2013
If (isset($_GET['country']) && isset($_GET['year'])) {
$tab = 'country = $_GET['country'] and year = $_GET['year']';
} elseif (isset($_GET['country'])) {
$tab = 'country = $_GET['country']';
} else {
echo 'Error';
}
Then I do:
$sql = 'select * from table where :sub;
$fetchData = $conn->prepare($sql);
$fetchData->bindParam(':sub',$tab);
Somehow, this will not work, even though the entire sql statement gets
constructed. Is there anyway I can do something like this using PDO?
No comments:
Post a Comment