Skip to content

Instantly share code, notes, and snippets.

@tps2015gh
Created April 12, 2017 05:24
Show Gist options
  • Save tps2015gh/e6e0fa31fc8edae4ada80bc9f8ce9122 to your computer and use it in GitHub Desktop.
Save tps2015gh/e6e0fa31fc8edae4ada80bc9f8ce9122 to your computer and use it in GitHub Desktop.
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'myuser',
password : 'mypass',
database : 'db1',
charset : 'utf8_general_ci'
});
connection.connect();
connection.query('SELECT count(*) AS solution from table_user', function (error, results, fields) {
if (error) throw error;
console.log('The solution is: ', results[0].solution);
});
connection.query('SELECT id ,fullname from table_user', function (error, results, fields) {
if (error) throw error;
//console.log(fields);
var i ;
for( i = 0 ; i < results.length ; i ++ ){
var row = results[i];
console.log('>> ', row.id , row.fullname);
}
});
for( i = 1 ; i <10; i ++ ){
connection.query('SELECT 1 + ' + i + ' AS solution', function (error, results, fields) {
if (error) throw error;
console.log('The solution is: ', results[0].solution);
});
}
connection.end();
{
"name": "nodejs_taxbreak",
"version": "1.0.0",
"description": "",
"main": "app1.js",
"dependencies": {
"mysql": "^2.13.0"
},
"devDependencies": {
"mysql": "^2.13.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Thitipong Samranvanich ",
"license": "ISC"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment