我想用nodejs使用mysql:試圖運行查詢:select count(*) from TABLE
。 結果出來作爲一個簡單的Nodejs MySQL查詢
[ RowDataPacket { 'count(*)': 33 } ]
我只想要33的答案時,JavaScript框架代碼如下所示
var express = require('express');
var router = express.Router();
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "honolulu",
password: "honolulu",
database: "db"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected to question database file 1!");
});
var but=20
con.query('select count(*) from qpsc',function (err, result) {
if (err) throw err;
but=result;
console.log(but);
});
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
router.get('/file', function(req, res, next) {
res.render('index2',{ num_buttons: '20'});
// console.log("RENDERED FROM INDEX.js");
});
module.exports = router;
所以,我應該怎麼辦? 請幫忙。