SHARE
TWEET

NodeJS : MYSQL Tampil Data , Input Data, Test Koneksi

stevennathaniel May 19th, 2016 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var mysql = require('mysql');
  2. var connection = mysql.createConnection({
  3.     host: 'localhost',
  4.     user: 'root',
  5.     password: 'kucing',
  6.     database: 'latihan'
  7. })
  8.  
  9. connection.connect(function(err) {
  10.     if (err) throw err
  11.     console.log('Anda sedang terhubung ...')
  12.    
  13.     //connection.query('INSERT INTO pelanggan(idpelanggan,namaawal,namaakhir,alamat,negara,kodepos,email,telepon,kota,tambahmailinglist,catatanpelanggan) VALUES (?,?,?,?,?,?,?,?,?,?,?)',['P0002','jhon', 'kenedy', 'batu ampar rt 20 no 2', 'indonesia', '76111', 'jhon@bpp.com', '054271134', 'balikpapan', 'tidak', 'pelanggan baru'], function(err, result) {
  14.         //if(err) throw err
  15.    
  16.     connection.query('SELECT * FROM pelanggan', function(err, results) {
  17.         if(err) throw err
  18.         console.log(results[0].idpelanggan)
  19.         console.log(results[0].namaawal)
  20.         console.log(results[0].namaakhir)
  21.        
  22.         console.log(results[1].idpelanggan)
  23.         console.log(results[1].namaawal)
  24.         console.log(results[1].namaakhir)
  25.        
  26.         connection.end();
  27.        
  28.     // })
  29.     })
  30. });
  31.  
  32. // connection.end();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top