“Node MySQL” Réponses codées

nœud et mysql comme

   return db.query(`SELECT * FROM user WHERE fullname LIKE N'%${data.fullname}%' ORDER BY create_time DESC LIMIT ?, ? `, [data.start,data.limit], callback);
Poised Parrot

Comment gérer une connexion DB dans JavaScript


//put these lines in a seperate file
const mysql = require('mysql2');

const connection = mysql.createPool({
    host: "localhost",
    user: "",
    password: "",
    database: ""
    // here you can set connection limits and so on
});

module.exports = connection;

//put these on destination page
const connection = require('../util/connection');

async function getAll() {
    const sql = "SELECT * FROM tableName";
    const [rows] = await connection.promise().query(sql);
    return rows;
} 
exports.getAll = getAll;
Alive Anaconda

Node MySQL

const mysql = require("mysql");
const mysqlDb = mysql.createConnection({
	host: process.env.mysql_HOST || "localhost",
	user: process.env.mysql_USER || "root",
	password: process.env.mysql_PASSWORD || "",
	database: process.env.mysql_DATABSE || "my_db"
});

mysqlDb.connect(err => {
	if(err) throw err;
});

module.exports = mysqlDb;
Heenok

noeud mysql

git clone https://github.com/LloydJanseVanRensburg/Node-Express-starter.git
Niraj Kafle

Réponses similaires à “Node MySQL”

Questions similaires à “Node MySQL”

Plus de réponses similaires à “Node MySQL” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code