zzarbi

Node.js/Mysql

Feb 2nd, 2012
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var sys = require('sys'),
  2. http = require('http'),
  3. mysql = require('mysql');
  4.  
  5. http.createServer(function(req, res) {
  6.     var client = mysql.createClient({
  7.           user: 'root',
  8.           password: '',
  9.     });
  10.     client.query('USE mongo');
  11.     client.query(
  12.           'SELECT * FROM basic WHERE id = '+Math.floor(Math.random()*100000),
  13.           function selectCb(err, results, fields) {
  14.             if (err) {
  15.               client.end();
  16.               res.writeHead(200, {'Content-Type': 'text/html'});
  17.               res.write('Bad');
  18.               res.end();
  19.               throw err;
  20.             }
  21.  
  22.             res.writeHead(200, {'Content-Type': 'text/html'});
  23.             res.write('Gooood');
  24.             res.end();
  25.             client.end();
  26.           }
  27.         );
  28.    
  29.    
  30. }).listen(8080);
Advertisement
Add Comment
Please, Sign In to add comment