如何使用Nodejs Server连接openshift Phpmyadmin数据库?

时间:2016-12-29 03:48:56

标签: node.js openshift

  

如何使用nodejs服务器连接“openshift phpmyadmin数据库”   下面是我的代码......我没有从数据库中得到结果...

     

日志:   成功{ “字段计数”:0 “affectedRows”:0 “insertId”:0 “serverStatus”:2“,warningCo   UNT “:0,” 消息 “:””, “protocol41”:真 “changedRows”:0}

 var connection = mysql.createConnection({

    OPENSHIFT_NAMMAOORU_DB_HOST :'127.4.188.2',
    OPENSHIFT_NAMMAOORU_DB_PORT :'3306',
    OPENSHIFT_NAMMAOORU_DB_USERNAME:'adminfxxxxx',
    OPENSHIFT_NAMMAOORU_DB_PASSWORD:'xxxxxxxxx',
    OPENSHIFT_NAMMAOORU_DB_URL:'mysql://adminxxxx:xxxxxxx@127.4.188.2:3306',


    //database:'nammaooru'


    });


    connection.connect(function(err,success){
      if (err) {
        throw err;
      console.log("Error"+JSON.strinerr);

      }
      else
      {
        console.log("Success"+JSON.stringify(success));
      }
    });

app.get('/city',function(req,res){
try{



  //var id = req.query.id;

/*var t=req.query.id;
console.log(t);
*/  /*  var data = {
        "error":1,
        "Books":""
    };*/


    console.log(req.params.cityid);
    var t=1;
    connection.query("SELECT * from city",function(err, rows, fields){

console.log("success"+JSON.stringify(rows));

//console.log("success"+JSON.stringify(fields));
//console.log(JSON.stringify(rows));
res.send(JSON.stringify(err));
//console.log("success"+JSON.stringify(err));

    });

}
catch(e)
{
console.log(e); 
}

});

本地休息网址 http://localhost:8000/city

  

{code:“ER_NO_DB_ERROR”,错误号:1046,sqlState:“3D000”,索引:0}

2 个答案:

答案 0 :(得分:0)

我认为您没有正确创建mysql连接:

var connection = mysql.createConnection({
    host: '127.4.188.2',
    user: 'adminfxxxxx'',
    password: 'xxxxxxxxx',
    port: 3306
});

答案 1 :(得分:0)

试试这个,只需添加数据库名称,如下所示

var connection = mysql.createConnection({

<form action="/path/to/server/" method="POST">

  <div id="screen">
    <label for="image"></label>
    <label for="image"></label>
    <label for="image"></label>
    <input type="text" 
           id="image" 
           class="number"
           name="number" 
           value="1"            
           maxlength="0" 
           style="appearance:button;width:50px;height:50px;" />
    <!-- border:none;outline:none; -->
    <!--
    <button class="number">
    <img src="img/1.png" />1
    </button>
   -->
    <input type="submit">
  </div>
</form>
<script>
  document.querySelector("#screen > .number")
  .addEventListener("click", function(event) {
    for (let label of event.target.labels) {
          label.innerHTML = event.target.value;
    }
  });
</script>