dsq2015 2016-08-11 13:24
浏览 35

无法使用codeigniter与node.js连接

I am building a voting system using codeigniter framework. There is a page in which I am showing a list of 10 people with there total vote and I wanted to make these voting count in realtime e.g voting count should change when user votes.

Voting page

Now to make all the finalist total votes real time, I am using node.js but unfortunately the program is not getting the total count.

var express    = require("express");
var mysql      = require('mysql');

var connection      =    mysql.createConnection({
    host     : 'localhost',
    user     : 'root',
    password : '',
    database : 'voting_sys',
});

var app = express();

connection.connect(function(err){
if(!err) {
    console.log("Database is connected ... nn");    
} else {
    console.log("Error connecting database ... nn");    
}
});

app.get("/",function(req,res){
connection.query("SELECT count('*') as votes from voting where finalist_id_fk=1", function(err, rows, fields) {
connection.end();
  if (!err)
    console.log('The solution is: ', rows);
  else
    console.log('Error while performing Query.');
  });
});

app.listen(3000);

When I run this file it only show database is connection where as I want total votes

enter image description here Please help me. How can I achieve it and how can I run this node.js file.

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 fluent的在模拟压强时使用希望得到一些建议
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用
    • ¥15 Web.config连不上数据库
    • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
    • ¥15 怎么配置广告联盟瀑布流
    • ¥15 Rstudio 保存代码闪退