Nodejs教程
Nodejs Mysql
Nodejs MongoDB
Nodejs 对比

Node.js MySQL更新记录

Node.js MySQL更新记录

UPDATE命令用于更新表中的记录。
示例 :id为1的"employees"表中更新城市。
在DBexample文件夹中创建一个名为" update"的js文件,并将以下数据放入其中:
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "12345",
database: "lidihuo"
});
con.connect(function(err) {
if (err) throw err;
var sql = "UPDATE employees SET city = 'Delhi' WHERE city = 'Allahabad'";
con.query(sql, function (err, result) {
if (err) throw err;
console.log(result.affectedRows + " record(s) updated");
});
});
现在打开命令终端并运行以下命令:
Node update.js
它将把ID 1的城市更改为在阿拉哈巴德之前的德里。
Node.js更新记录1
您可以在新表中检查更新的记录:
Node.js更新记录2
在旧表城市" Ajeet Kumar"是阿拉哈巴德。
Node.js更新记录3
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4