繁体   English   中英

将Hostinger DB与node.js连接

[英]Connect hostinger DB with node.js

我在Hostinger.com上有一个MySQL数据库设置。 我可以使用PHP轻松访问数据库,但是当我尝试使用node.js代码访问数据库时,会抛出错误。

我的node.js代码:

app.get('/hostinger', function(request, response) {
    response.send("Hello");
    var connection = mySequel.createConnection({
        host: "mysql.hostinger.in",
        user: "u**********j",
        password: "*****",
        database: "u**********j"
    });
    connection.connect();
    var buery = "select * from testing";
    connection.query(buery, function(error, result, fields) {
        if (error) {
            console.log(error);
        } else {
            response.send(result);
            console.log(result);
        }
    })
    connection.end();
    // console.log("This is received via a get request in hostinger");
});

我得到的错误是:

"117.193.192.51" dyno=web.1 connect=0ms service=2ms status=304 bytes=149 protocol=https
2017-04-23T17:59:49.759522+00:00 app[web.1]: { Error: getaddrinfo ENOTFOUND mysql.hostinger.in mysql.hostinger.in:3306
2017-04-23T17:59:49.759532+00:00 app[web.1]:     at errnoException (dns.js:28:10)
2017-04-23T17:59:49.759533+00:00 app[web.1]:     at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
2017-04-23T17:59:49.759534+00:00 app[web.1]:     --------------------
2017-04-23T17:59:49.759537+00:00 app[web.1]:     at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:141:48)
2017-04-23T17:59:49.759538+00:00 app[web.1]:     at Protocol.handshake (/app/node_modules/mysql/lib/protocol/Protocol.js:52:41)
2017-04-23T17:59:49.759538+00:00 app[web.1]:     at Connection.connect (/app/node_modules/mysql/lib/Connection.js:130:18)
2017-04-23T17:59:49.759539+00:00 app[web.1]:     at /app/index.js:29:16
2017-04-23T17:59:49.759540+00:00 app[web.1]:     at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2017-04-23T17:59:49.759540+00:00 app[web.1]:     at next (/app/node_modules/express/lib/router/route.js:137:13)
2017-04-23T17:59:49.759541+00:00 app[web.1]:     at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
2017-04-23T17:59:49.759542+00:00 app[web.1]:     at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2017-04-23T17:59:49.759542+00:00 app[web.1]:     at /app/node_modules/express/lib/router/index.js:281:22
2017-04-23T17:59:49.759543+00:00 app[web.1]:     at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
2017-04-23T17:59:49.759544+00:00 app[web.1]:   code: 'ENOTFOUND',
2017-04-23T17:59:49.759544+00:00 app[web.1]:   errno: 'ENOTFOUND',
2017-04-23T17:59:49.759545+00:00 app[web.1]:   syscall: 'getaddrinfo',
2017-04-23T17:59:49.759545+00:00 app[web.1]:   hostname: 'mysql.hostinger.in',
2017-04-23T17:59:49.759546+00:00 app[web.1]:   host: 'mysql.hostinger.in',
2017-04-23T17:59:49.759547+00:00 app[web.1]:   port: 3306,
2017-04-23T17:59:49.759548+00:00 app[web.1]:   fatal: true }

从错误日志判断,我可以看到主机无法正确解析,当我在PHP文件中提供相同的凭据并执行该主机时,便能够无任何错误地运行它。

我的代码可能是什么问题? 另外,我在00webhost00webhost ,node.js无法用于访问数据库。 Hostinger网站上未提及此类事情。 如果是这样,那么是否有任何PaaS服务提供可以轻松与node.js连接的MySQL数据库?

您是否在帐户“ Databases>Remote MySQL部分中设置了远程MySQL连接? mysql.hostinger.in url用于本地连接。 如果您使用node.js应用程序,那么您是从外部源进行连接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM