选择查询的学说问题

时间:2014-10-13 10:50:35

标签: mysql pdo doctrine-orm

DBALException: An exception occurred while executing 'SELECT
    s.name,
    s.id,
    s.title,
    su.username,
    su.id,
    a.time created
FROM activities a
INNER JOIN users u
    ON u.username = ?
INNER JOIN shots s
    ON s.id = a.object_id
INNER JOIN users su
    ON su.id = s.user_id
WHERE a.user_id = u.id
    AND a.object = 2
    AND a.action = ?
ORDER BY a.time DESC
LIMIT ?' with params ["Dorah", "7", "5"]:

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 ''5'' at line 19

如果我使用此源代码执行查询,则会出现错误:

$sql = 'SELECT
            s.name,
            s.id,
            s.title,
            su.username,
            su.id,
            a.time created
        FROM activities a
        INNER JOIN users u
            ON u.username = :username
        INNER JOIN shots s
            ON s.id = a.object_id
        INNER JOIN users su
            ON su.id = s.user_id
        WHERE a.user_id = u.id
            AND a.object = 2
            AND a.action = :action
        ORDER BY a.time DESC
        LIMIT :limit';

$values = array(
    'username' => $username,
    'action' => $action,
    'limit' => $limit
);

$types = array(
    'action' => \PDO::PARAM_INT,
    'limit' => \PDO::PARAM_INT
);

$stmt = $this->conn->executeQuery($sql,$values,$types);
$data = $stmt->fetchAll();

我将Doctrine与Miniframework Silex一起使用。我找到了解决这个意外错误的方法。任何想法,关于如何解决这个问题?

请提供具体的提示和帮助! THX

0 个答案:

没有答案