Sunday 19 March 2017

Getting a database does not exist error for a database that exists

I am trying to connect node with mysql. I have created the code for the connection and using phpmyadmin created a database called sampleDB. When I try to connect I get an Error: ER_BAD_DB_ERROR: Unknown database 'sampledb'. But I have created the database.

Here is my code

var express = require('express');
var mysql = require('mysql');
var app = express()

var connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '',
    database: 'sampleDB'
});

connection.connect(function(error){
    if(!!error){
        console.log(error);
    } else {
        console.log('Connected')
    }
})

app.get('/', function(req, resp){
    connection.query("Select * from mySampleTable", function(error, rows, fields){
        if(!!error){
            console.log('Error in query')
        }else {
            console.log('Success');
        }
    });
})

app.listen(1337);

Here is an image of of the db I created call sampleDB. enter image description here

So if I created the db called sampleDB, why am I getting an error that the sampledb table does not exist?



via Aaron

No comments:

Post a Comment