Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

node js get data from mysql

var mysql = require('mysql');

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

connection.connect();

connection.query('SELECT * FROM test_table', function (err, rows, fields) {
  if (err) throw err;

  console.log('The solution is: ', rows[0].solution);
});

connection.end();
Comment

node js get data from mysql

To select data from a table in MySQL, use the "SELECT" statement.

example:
Select all records from the "customers" table, and display the result object:

var mysql = require('mysql');

var con = mysql.createConnection({
  host: "localhost",
  user: "yourusername",
  password: "yourpassword",
  database: "mydb"
});

con.connect(function(err) {
  if (err) throw err;
  con.query("SELECT * FROM customers", function (err, result, fields) {
    if (err) throw err;
    console.log(result);
  });
});

SELECT * will return all columns
Comment

PREVIOUS NEXT
Code Example
Javascript :: get input in terminal nodejs 
Javascript :: console.log regex 
Javascript :: short date angular pipe 
Javascript :: connecting to mongodb using mongoose 
Javascript :: conditionally set checkbox state in React 
Javascript :: javascript current time 
Javascript :: javascript generate random hex 
Javascript :: javascript float 2 decimal 
Javascript :: hover event javascript 
Javascript :: discord.js message on member add 
Javascript :: js input validate excel file type 
Javascript :: monitor changes made to object 
Javascript :: protractor get active element 
Javascript :: scss mute warnings 
Javascript :: remove disabled js 
Javascript :: get channel id discord js v12 
Javascript :: how to use componentdidmount in functional component 
Javascript :: check if a string is alphanumeric 
Javascript :: jquery dblclick 
Javascript :: insertone mongoose 
Javascript :: Twilio room does not disconnect / Webcam LED remains on 
Javascript :: WWW.$JavaJavaGRIPPER.DOWNLOAD 
Javascript :: react get data attribute from element 
Javascript :: visual code put quotes to each line 
Javascript :: js nested backticks 
Javascript :: how to calculate average of array in javascript 
Javascript :: generate random brightest color 
Javascript :: puppeteer inner text 
Javascript :: how to terminate a program in js 
Javascript :: rotate a div using javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =