我使用AJAX将数据“获取”到我的Node Client中,但我似乎无法弄清楚如何将这些数据“POST”到MySQL。有什么想法吗?
答案 0 :(得分:0)
您可以使用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.');
});