Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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
 
PREVIOUS NEXT
Tagged: #node #js #data #mysql
ADD COMMENT
Topic
Name
3+3 =