[EDIT] Removed parametrized table name and altered values of order and minimum rating count to distinguish values [/EDIT]
I have a simple table with following create table
CREATE TABLE ratings_cache (
id INT NOT NULL AUTO_INCREMENT,
movie_id INT NOT NULL,
movie_title VARCHAR(128),
rating DECIMAL(5,4),
rating_count INT DEFAULT 0,
PRIMARY KEY (`id`)
);
Now, I want to query it using Doctrine with some parameters (app
is Silex application of course):
$sql = "
SELECT ratings_cache.*
FROM :table_name
WHERE rating_count > :min_rankings
ORDER BY rating DESC, rating_count DESC
LIMIT :limit";
$stmt = $this->app['db']->prepare($sql);
$stmt->bindValue(':min_rankings', $this->minRanks);
$stmt->bindValue('limit', $this->limit);
return $stmt->execute()->fetchAll();
As you can see the query in this form is simple and it runs smoothly when I run it through Mysql console but when I run the code above I get following error:
An exception occurred while executing '
SELECT *
FROM ratings_cache
WHERE rating_count > :min_rankings
ORDER BY rating DESC, rating_count DESC
LIMIT :limit' with params [20, 30]:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''30'' at line 5
I realize the problem might be with something trivial but I am not very used to Doctrine (usualy prefer handling queries on my own) and simply don't know what might be wrong here...