Wednesday 1 November 2017

node.js - How to query data from MySQL through Node

I'm new to Node and learning how to query data from
MySQL.

I get the following
error:




err {
[Error: ER_BAD_DB_ERROR: Unknown database '201803028']
code:
'ER_BAD_DB_ERROR',
errno: 1049,
sqlMessage: 'Unknown database
\'201803028\'',
sqlState: '42000',
fatal: true
}





here
is my code




const
mysql = require('mysql');



var db =

mysql.createConnection({
host:'localhost',

user:'root',

password:'123456',
database:'201803028'});



db.query('SELECT * FROM
user-table;',(err,data)=>{
if(err){

console.log('err',err);
}else{
console.log('success',data);

}

})





Could
anyone tell me what's the matter with my
coding?



Thank you very
much!

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...