Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- npm install mysql
- const mySQL = require('mysql');
- const mySQLCon = mySQL.createConnection({
- host: "localhost",
- user: "username",
- password: "password",
- database: "databaseName"
- });
- function connectTest() {
- mySQLCon.connect(function(err) {
- if(err){
- console.log(err.code);
- console.log(err.fatal);
- }
- });
- console.log(mySQLCon.state);
- sSQL = "SELECT sField FROM tblName WHERE iID = 1";
- mySQLCon.query(sSQL, function(err, rows, fields) {
- if(err){
- console.log("An error ocurred performing the query.");
- return;
- }
- if (rows.length > 0) {
- console.log(rows[0].sField);
- } else {
- console.log("No Records found!");
- }
- });
- mySQLCon.end(function(){
- // The connection has been closed
- });
- }
- connectTest()
- console.log(mySQLCon.state);
Add Comment
Please, Sign In to add comment