duanbage2161
duanbage2161
2017-03-11 17:02

如何使用socket和mysql发送多个值来存储在数据库中

  • php
  • mysql
  • sockets
  • jquery

I'm using this code and it's working fine with parameter value to store in database, but i want to store 2 more values in database how i can pass multiple values in database by using socket.. here is code...

    io.on('connection',function(socket){  
    console.log("A user is connected");
    socket.on('status added',function(status){
      add_status(status,function(res){

        if(res){
            io.emit('refresh feed',status);
        } else {
            io.emit('error');
        }
      });
    });
});

var add_status = function (status,callback) {
    pool.getConnection(function(err,connection){
        if (err) {
          callback(false);
          return;
        }
    connection.query("INSERT INTO `status` (`s_text`) VALUES ('"+status+"')",function(err,rows){
            connection.release();
            if(!err) {
              callback(true);
            }
        });
     connection.on('error', function(err) {
              callback(false);
              return;
        });
    });
}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答