0

I'm trying to print the query but it doesn't show nothing. I cant't to figure out why the code doesn't work. The connection works but the query doesn't.

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

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

connection.query('USE database');

app.set('port', 3001);

app.get('/',function(req, res) {
  connection.query('SELECT * from test', function(err, rows, fields) {
    if (err) throw err;
    console.log('this is the result = ', rows[0].field);
  });
});

1 Answer 1

1

You have to connect to the database, by writing:

connection.connect();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.