-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestdb.js
More file actions
35 lines (29 loc) · 1.06 KB
/
testdb.js
File metadata and controls
35 lines (29 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require('dotenv').config(); // 환경 변수 로드
const mysql = require('mysql2/promise');
// MySQL DB 연결
let test = async () => {
const db = mysql.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PW,
port: process.env.DB_PORT,
database: process.env.DB_NAME,
waitForConnections: true,
insecureAuth: true
});
// 데이터 삽입 (INSERT INTO)
//let insertSql = 'INSERT INTO subscriber (name, email, zipCode) VALUES (?, ?, ?)';
//let values = ['sswu', 'sswu@sungshin.ac.kr', '12345']; // 삽입할 데이터
try {
// 데이터 삽입
const [result] = await db.execute(insertSql, values);
console.log('데이터 삽입 성공:', result);
} catch (err) {
console.error('삽입 중 오류 발생:', err);
}
// 데이터 조회 (SELECT)
let selectSql = 'SELECT * FROM users';
let [rows, fields] = await db.query(selectSql);
console.log('현재 subscriber 테이블의 데이터:', rows);
};
test();