SQL语法错误 - 语法错误或访问冲突:1064

时间:2014-03-31 08:21:43

标签: php sql

我正在尝试运行此SQL查询:

$stmt = $pdo_conn->prepare("SELECT * from voipwallboard_ast_queue_log where time = :time, callid = :callid, queuename = :queuename, agent = :agent, event = :event, arg1 = :arg1, arg2 = :arg2, arg3 = :arg3, queue_id = :queue_id ");
        $stmt->execute(array(':time' => $result["time"], 
        ':callid' => $result["callid"], 
        ':queuename' => $result["queuename"], 
        ':agent' => $result["agent"], 
        ':event' => $result["event"], 
        ':arg1' => $result["arg1"], 
        ':arg2' => $result["arg2"], 
        ':arg3' => $result["arg3"], 
        ':queue_id' => $result["queue_id"] ));

但我得到错误:

Fatal error: Uncaught exception 'PDOException' with message '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 ' queuename = '0899*400', agent = 'NONE', event = 'ENTERQUEUE', arg1 = '', arg2 =' at line 1' in /home/integra/public_html/callstats/copy/copy.php:57 Stack trace: #0 /home/integra/public_html/callstats/copy/copy.php(57): PDOStatement->execute(Array) #1 {main} thrown in /home/user/public_html/callstats/copy/copy.php on line 57

我找不到问题所在?

3 个答案:

答案 0 :(得分:2)

您不使用,加入WHERE语句。您使用ANDOR

SELECT 
    * 
FROM
    voipwallboard_ast_queue_log 
WHERE
    time = :time
AND
    callid = :callid
AND
    queuename = :queuename
AND
    agent = :agent
AND
    event = :event
AND
    arg1 = :arg1
AND
    arg2 = :arg2
AND
    arg3 = :arg3
AND
    queue_id = :queue_id

答案 1 :(得分:0)

在WHERE语句中,应通过OR或AND运算符连接多个条件

stmt = $pdo_conn->prepare("SELECT * from voipwallboard_ast_queue_log 
            where time = :time AND callid AND .........

答案 2 :(得分:0)

你的语法错了。您需要指定where子句中的项目如何协同工作 - 即ANDOR

SELECT * from voipwallboard_ast_queue_log 
where time = :time AND callid = :callid AND queuename = :queuename AND agent = :agent AND event = :event AND arg1 = :arg1 AND arg2 = :arg2 AND arg3 = :arg3 AND queue_id = :queue_id