Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mysql = require("mysql");
- var app = require('express')();
- var http = require('http').Server(app);
- var io = require('socket.io')(http);
- app.get('/', function(req, res){
- res.sendfile('testsql.html');
- //res.sendfile('/login/');
- });
- http.listen(3000, function(){
- console.log('listening on *:3000');
- });
- // First you need to create a connection to the db
- var con = mysql.createConnection({
- host: "stuff",
- user: "stuff",
- password: "stuff"
- });
- con.connect(function(err){
- if(err){
- console.log('Error connecting to Db');
- return;
- }
- console.log('Connection established');
- });
- con.end(function(err) {
- // The connection is terminated gracefully
- // Ensures all previously enqueued queries are still
- // before sending a COM_QUIT packet to the MySQL server.
- });
- var con = mysql.createConnection({
- host: "stuff",
- user: "stuff",
- password: "stuff",
- database: "stuff"
- });
- con.query('SELECT * FROM users',function(err,rows){
- if(err) throw err;
- console.log('Data received from Db:n');
- console.log(rows);
- });
- io.on('connection', function (rows) {
- socket.brodcast.emit('showrows', rows);
- });
- <html>
- <body>
- <p>it Works<p>
- <div id="display">
- </div>
- </body>
- </html>
- <script>
- var socket = io();
- socket.on('connection', function(rows){
- jQuery("#display").append(rows);
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement