Created
April 8, 2019 20:39
-
-
Save getnamo/d21b42de4384bdba339120e3064ab9da to your computer and use it in GitHub Desktop.
sample sql query callback on node.js
This file contains 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
//assuming you're using https://www.npmjs.com/package/mysql | |
const mysql = require('mysql'); | |
const con = mysql.createConnection({ | |
host: "localhost", | |
user: "yourusername", | |
password: "yourpassword", | |
database: "mydb" | |
}); | |
socket.on('sqlQuery', function(queryData, callback){ | |
//we assume you pass a json with | |
//{"column": "*", "table": "users", "condition":"User=Bob"} | |
//run the query | |
con.query("SELECT" + queryData.column + " FROM " + queryData.table + " WHERE " + queryData.condition, function (err, result, fields) { | |
if (err) throw err; | |
console.log(result); | |
//callback with result to ue4 | |
callback(result); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍