有没有人用Node.JS来更新MySQL

时间:2021-01-07 00:13:31

I use AJAX to "GET" data into my Node Client, but I cant seem to figure out how to "POST" that data to MySQL. Any ideas?

我使用AJAX将数据“获取”到我的Node Client中,但我似乎无法弄清楚如何将这些数据“POST”到MySQL。有任何想法吗?

1 个解决方案

#1


0  

You can use mysql npm module: npm install mysql

你可以使用mysql npm模块:npm install mysql

var mysql      = require('mysql');
var pool = mysql.createPool({
    host: 'localhost'
    user: 'youruser'
    password: 'yourpassword' 
    database: 'yourdb'
});

pool.getConnection(function (err, connection) {
    connection.query('INSERT INTO tbl_name (col1,col2) VALUES(' + theValueYouGotFromAjax + ',' + anotherValue + ')' + '\'', function (err, result) {
            if (err) console.log(err);
            console.log('Created ' + result.affectedRows + ' rows');
            connection.release();
            console.log('Connection returned to pool.');
});

Check module documentation: https://github.com/mysqljs/mysql/tree/v0.9

检查模块文档:https://github.com/mysqljs/mysql/tree/v0.9

#1


0  

You can use mysql npm module: npm install mysql

你可以使用mysql npm模块:npm install mysql

var mysql      = require('mysql');
var pool = mysql.createPool({
    host: 'localhost'
    user: 'youruser'
    password: 'yourpassword' 
    database: 'yourdb'
});

pool.getConnection(function (err, connection) {
    connection.query('INSERT INTO tbl_name (col1,col2) VALUES(' + theValueYouGotFromAjax + ',' + anotherValue + ')' + '\'', function (err, result) {
            if (err) console.log(err);
            console.log('Created ' + result.affectedRows + ' rows');
            connection.release();
            console.log('Connection returned to pool.');
});

Check module documentation: https://github.com/mysqljs/mysql/tree/v0.9

检查模块文档:https://github.com/mysqljs/mysql/tree/v0.9