Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mysql query node.js

const mysql=require('mysql2')

const connection = mysql.createPool({
    host: 'localhost',
    user:'root',
    password:'whatever it is',
    database: "whatever it is"
})

const sqlInsert = 'INSERT INTO reviews (fieldName1, fieldName2) values (?, ?)' // whatever query you want
connection.query(
  sqlInsert,
  [value1, value2], // inserts into '?' symbol
  (err, results, fields) => {
    if(err){
      console.log(err)
    }
    else{
      console.log(results)
    }
  }
)
Comment

nodejs mysql query

//The second form .query(sqlString, values, callback) comes when using placeholder values 
connection.query('SELECT * FROM `books` WHERE `author` = ?', ['David'], function (error, results, fields) {
  // error will be an Error if one occurred during the query
  // results will contain the results of the query
  // fields will contain information about the returned results fields (if any)
});

//The third form .query(options, callback) comes when using various advanced options on the query
connection.query({
  sql: 'SELECT * FROM `books` WHERE `author` = ?',
  timeout: 40000, // 40s
  values: ['David']
}, function (error, results, fields) {
  // error will be an Error if one occurred during the query
  // results will contain the results of the query
  // fields will contain information about the returned results fields (if any)
});
Comment

nodejs mysql

// you can't connect to mysql in client side js

// but you can use it in nodejs which is server-side
// for nodejs you can use package named mysql2
npm i mysql2

// read Doc here 
// https://www.npmjs.com/package/mysql2
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript check negative number 
Javascript :: try catch javascript 
Javascript :: image to base64 js 
Javascript :: mongodb findoneandupdate return new document 
Javascript :: for loop on array in javascript 
Javascript :: angularjs 
Javascript :: json example list of objects 
Javascript :: discord js embed footer 
Javascript :: URLSearchParams for query params 
Javascript :: how to check if an array contains a number in javascript 
Javascript :: React social login button 
Javascript :: react native pure component vs component 
Javascript :: fix slow loading images in react 
Javascript :: xml vs json 
Javascript :: js range similar to python 
Javascript :: Expresion regular para validar Dirección URL 
Javascript :: round down javascript 
Javascript :: countdown recursion javascript 
Javascript :: javascript detect back space 
Javascript :: how to mark a icon with vector icons in mapview 
Javascript :: import objectdoesnotexist 
Javascript :: file upload nest 
Javascript :: get max number in array 
Javascript :: how to find reverse of a number in javascript 
Javascript :: apar chinmoy phy js code 
Javascript :: mongoose search multiple fields 
Javascript :: yt playlist downloader js 
Javascript :: recursive function scheme 
Javascript :: chrome extension inject html 
Javascript :: node js mysql variables 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =