From 266307da9c6d3332eb55603914f7e9a4ae725d94 Mon Sep 17 00:00:00 2001
From: Panyaphorn Promchat <65160014@go.buu.ac.th>
Date: Wed, 26 Mar 2025 10:51:07 +0700
Subject: [PATCH] Initial commit

---
 app.js | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/app.js b/app.js
index fae6bb3..dcc8379 100644
--- a/app.js
+++ b/app.js
@@ -5,7 +5,7 @@ const app = express();
 const port = 3000;
 
 // การตั้งค่าการเชื่อมต่อฐานข้อมูล MySQL (ใช้ pool)
-const db = mysql.createConnection({
+const db = mysql.createPool({
   host: process.env.DB_HOST,
   port: process.env.DB_PORT,
   user: process.env.DB_USER,
@@ -17,14 +17,14 @@ const db = mysql.createConnection({
 });
 
 // Test the database connection to ensure everything is set up correctly
-db.connect(err => {
+db.getConnection((err, connection) => {
   if (err) throw err;
   console.log("Connected to the database.");
+  connection.release(); // Release the connection back to the pool
 });
 
 module.exports = { db };
 
-
 // การตั้งค่า Express session
 app.use(session({
     secret: 'your_secret_key',
@@ -55,8 +55,8 @@ app.get('/', (req, res) => {
 app.use('/auth', require('./routes/auth'));
 app.use('/admin', require('./routes/admin'));
 app.use('/customer', require('./routes/customer'));
-  
+
 // Starting the server
 app.listen(port, () => {
     console.log(`Server is running on http://localhost:${port}`);
-});
\ No newline at end of file
+});
-- 
GitLab