Created
April 3, 2017 18:51
-
-
Save ofanidariyan/466031fa27205c15b7711b9cfa9e7bb0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mysql = require('mysql'); | |
var express = require('express'); | |
var connection = mysql.createConnection({ | |
host: 'localhost', | |
user: 'root', | |
database: 'injection', | |
password: '', | |
multipleStatements: true // Mengaktifkan eksekusi multiple statement | |
}); | |
connection.connect(function(err){ | |
if(!err) { | |
console.log("Berhasil terkoneksi dengan database !!!"); | |
} else { | |
console.log("Gagal terkoneksi dengan database !!!"); | |
} | |
}); | |
var app = express(); | |
app.get('/:id', function(req, res, next) { | |
//Query SQL yang tidak terfilter dengan benar | |
connection.query('SELECT * FROM users WHERE id="' + req.param('id') + '"', function(err, rows, fields) { | |
if (err) { | |
next(err); | |
return; | |
} | |
res.send(JSON.stringify(rows)); | |
}); | |
}); | |
app.listen(3000); | |
console.log('Server Berjalan Port 3000 :)'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment