带有绑定参数的Doctrine Silex查询失败

时间:2017-09-23 15:57:55

标签: php mysql doctrine-orm silex named-parameters

[编辑]删除参数化表名称和更改的订单值和最小评级计数以区分值[/ EDIT]

我有一个包含以下创建表的简单表

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`)
);

现在,我想使用Doctrine查询一些参数(app当然是Silex应用程序):

$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();

正如您所看到的,这种形式的查询很简单,当我通过My​​sql控制台运行它时运行顺利,但是当我运行上面的代码时出现以下错误:

    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

我意识到问题可能是微不足道的但我不太习惯于学说(通常更喜欢自己处理查询)并且根本不知道这里可能有什么问题......

0 个答案:

没有答案