node.js - 2
2019.10.10 12:44
Node.js MySQL Update
조회 수 276 추천 수 0 댓글 0
Update Table
var mysql = require('mysql'); var con = mysql.createConnection({ host: "localhost", user: "yourusername", password: "yourpassword", database: "mydb" }); con.connect(function(err) { if (err) throw err; var sql = "UPDATE customers SET address = 'Canyon 123' WHERE address = 'Valley 345'"; con.query(sql, function (err, result) { if (err) throw err; console.log(result.affectedRows + " record(s) updated"); }); });
C:\Users\Your Name>node demo_db_update.js
1 record(s) updated
UPDATE 구문은 WHERE문이 함께 사용되지 않으면 매우 위험합니다.
The Result Object
{ fieldCount: 0, affectedRows: 1, insertId: 0, serverStatus: 34, warningCount: 0, message: '(Rows matched: 1 Changed: 1 Warnings: 0', protocol41: true, changedRows: 1 }
console.log(result.affectedRows)
1
번호 | 분류 | 제목 | 날짜 | 조회 수 |
---|---|---|---|---|
38 | node.js - 1 | Express에서 POST 방식 사용하기 | 2019.10.16 | 349 |
37 | node.js - 1 | Express에서 MySql 사용 | 2019.10.10 | 845 |
36 | node.js - 2 | Node.js MySQL Limit | 2019.10.10 | 288 |
» | node.js - 2 | Node.js MySQL Update | 2019.10.10 | 276 |
34 | node.js - 2 | Node.js MySQL Drop Table | 2019.10.08 | 357 |
33 | node.js - 2 | Node.js MySQL Delete | 2019.10.08 | 302 |
32 | node.js - 2 | Node.js MySQL Order By | 2019.10.08 | 285 |
31 | node.js - 2 | Node.js MySQL Where | 2019.10.08 | 494 |
30 | node.js - 2 | Node.js MySQL Select From | 2019.10.08 | 630 |
29 | node.js - 2 | Node.js MySQL Insert Into | 2019.10.01 | 933 |
28 | node.js - 2 | Node.js MySQL Create Table | 2019.10.01 | 324 |
27 | PUG | PUG 07 / INCLUDES | 2019.10.01 | 358 |
26 | PUG | PUG 06 / DOCTYPE | 2019.10.01 | 431 |
25 | node.js - 2 | Node.js MySQL | 2019.09.27 | 315 |
24 | node.js - 2 | NPM의 사용 | 2019.09.26 | 313 |
23 | node.js - 2 | Node.js URL Module | 2019.09.26 | 461 |
22 | PUG | PUG 05 / Conditionals | 2019.09.19 | 755 |
21 | PUG | PUG 04 / Comments | 2019.09.19 | 329 |
20 | PUG | PUG 03 / Code | 2019.09.19 | 691 |
19 | PUG | PUG 02 / Case | 2019.09.19 | 367 |