ER_PARSE_ERROR您的SQL语法有错误:从MySQL中选择整个表

时间:2019-04-19 22:22:24

标签: javascript mysql node.js

我首先看过类似的问题,但无法弄清楚如何更改代码以使其正常工作。我是Node.js和MySQL的新手。我遇到了这个错误: enter image description here 我的代码如下(我连接正常,只是更改了主机/密码信息):

    var mySQLpointer, connObj;

mySQLpointer = require("mysql");

connObj = mySQLpointer.createConnection( { 
    host:     "host", 
    user:     "user",
    password: "pw",
    database: "db"
} );

connObj.connect( function(err) {
    if (err) 
        // throw err; or use the follwowing command
        console.log("Connection Error: " + err.stack);
    else 
        // console.log("Connected to DB. :-)");
        console.log("Connection OK! ID = " + connObj.threadId);
});

let sqlStmt = "SELECT * FROM Product-Service";

connObj.query(sqlStmt, 
    function(err, dataSet, fields) {
        if (err)
            throw err;
        else {
            console.log(dataSet);
            }
        }
);


connObj.end();

我想做的是显示SQL表中的所有行和列,那里只有3行: enter image description here 理想情况下,我试图让它们像这样显示: enter image description here

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

由于-:

,您需要在表名周围加上反引号

let sqlStmt = "SELECT * FROM `Product-Service`";