【问题标题】:TypeError: Cannot set property 'decoder' of undefinedTypeError:无法设置未定义的属性“解码器”
【发布时间】:2014-03-06 12:47:31
【问题描述】:

我收到 TypeError: Cannot set property 'decoder' of undefined in following code。

var mysql = require('mysql');

//database connection
connection = mysql.createConnection({host: 'localhost', user: 'root', password: '********', database: '*******'});
connection.connect(function(err) {
 if (err) 
  console.log(err); 
 else 
  console.log("Connected to MySQL");  
});

exports.GetAllBlogsFromDb = function(req, res) {   
  var blogid = 1;
  var ListBlogs = 'SELECT `blogname` FROM `blogs` WHERE `blogid`=? LIMIT 1';
  connection.query(ListBlogs, [blogid], function(err, ResultBlogs) {
    if (err)
        console.log(err);
    else
        console.log("ResultBlogs");        
  });
};

【问题讨论】:

    标签: mysql database node.js


    【解决方案1】:

    我遇到了同样的问题,要解决它,只需升级 node.js

    # npm cache clean -f
    # npm install -g n
    # n stable
    

    我使用了 node.js v0.10.2,现在它在 v0.10.26 上运行良好

    【讨论】:

    • 感谢您的回复,但数据库连接有问题,我现在已经解决了。
    猜你喜欢
    • 2015-09-09
    • 2021-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-20
    • 2022-08-16
    相关资源
    最近更新 更多