数据库对齐(?)的Php SQL语法错误!

时间:2014-07-25 09:48:37

标签: php sql pdo shopware

如果我只是瞎了,我觉得这没有任何意义,因为我总是像这样写它而且我看到它有什么问题。除了我在语法中使用了多个SQL解决方案仍有错误...

我的PHP代码:

$sql1 = " SELECT table1.file_name, table2.path
                FROM table1 AS t1
                LEFT JOIN table2 AS t2
                ON t1.file_name = t2.path
                WHERE t2.path IS NULL OR t1.file_name <> t2.file_name OR t1.file_name <> t2.path";

    $sql2 = "INSERT INTO table3 (file_name) VALUES(".$sql1.")";

    Shopware()->Db()->query($sql2);

我的错误讯息:

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 'SELECT table1.file_name, table2.path FROM (the first 2 letters of table1)' at line 1 in Zend\Db\Statement\Pdo.php on line 234

1 个答案:

答案 0 :(得分:3)

INSERT..SELECT statements写成:

INSERT INTO ... SELECT ... FROM ...;

INSERT INTO ... VALUES (SELECT ... FROM ...);