0
votes

var mysql = require('mysql');

var connection = mysql.createConnection({

host : 'localhost',
user : 'root',
port : '3306',
password : 'root',
database : 'test'

});

connection.connect(function(err){

if(!err) {

    console.log("database is connected"+database);
} else {
    console.log("database is not connected"+err.message);
}

});

this is the error i got

1
It seems like database is not declared, are you sure this variable exists ?Sparw
the variable database in console.log("database is connected"+database); is undefined, you don't have such a variable in the scope, but seems that connection is successfulcodtex

1 Answers

0
votes

Change your connect function to look like this: (Replacing function with fat arrow function "=>")

connection.connect((err) => {
    if (!err) {
        console.log("database is connected"+database);
    } else {
        console.log("database is not connected"+err.message);
    }
});

This below link explains why:

What is the difference between () => {} and function() {} in react-native javascript?