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

PREVIOUS NEXT
Code Example
Javascript :: org.json.JSONException: End of input at character 0 of 
Javascript :: livewire file upload progress 
Javascript :: how to send a message to a discord server using a bot 
Javascript :: relode div 
Javascript :: Deleting all white spaces in a string 
Javascript :: node uuid 
Javascript :: speedtest-net node.js 
Javascript :: js select element by css selector 
Javascript :: get result and write to file node 
Javascript :: javascript date get future 15 minutes 
Javascript :: get data from url javascript 
Javascript :: multidimensional array push in jquery 
Javascript :: history.push 
Javascript :: javascript get element position relative to document 
Javascript :: smooth scroll to target with offset 
Javascript :: how to change text of div in javascript 
Javascript :: check date format javascript 
Javascript :: how to check if item is in list js 
Javascript :: check if message mentions users discord js 
Javascript :: get html tag javascript 
Javascript :: how to update kali linux on virtualbox 
Javascript :: formatting numbers as currency string 
Javascript :: js form serialize 
Javascript :: click outside javascript 
Javascript :: react native create shadows 
Javascript :: set timeout javascript 
Javascript :: firebase cloud functions schedule function run time 
Javascript :: custom login with facebook button react native 
Javascript :: settext javascript 
Javascript :: body click function removeclass 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =