Gitlab@Informatics
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
webposts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
65160258
webposts
Commits
09781c77
Commit
09781c77
authored
1 month ago
by
65160258
Browse files
Options
Downloads
Patches
Plain Diff
confdb
parent
0877e597
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
db.js
+22
-7
22 additions, 7 deletions
db.js
with
22 additions
and
7 deletions
db.js
+
22
−
7
View file @
09781c77
// db.js (การตั้งค่าฐานข้อมูล)
require
(
'
dotenv
'
).
config
();
// โหลดค่า environment variables
const
mysql
=
require
(
'
mysql2/promise
'
);
// สร้าง connection pool
const
pool
=
mysql
.
createPool
({
host
:
'
10.104.20.250
'
,
port
:
"
3306
"
,
user
:
'
ro
ot
'
,
password
:
'
TKAzta61467
'
,
database
:
'
club_db
'
,
host
:
process
.
env
.
DB_HOST
,
port
:
process
.
env
.
DB_PORT
,
user
:
p
ro
cess
.
env
.
DB_USER
,
password
:
process
.
env
.
DB_PASS
,
database
:
process
.
env
.
DB_NAME
,
});
module
.
exports
=
pool
;
\ No newline at end of file
// ตัวอย่างการใช้งาน async/await เพื่อเชื่อมต่อ
async
function
connectDatabase
()
{
try
{
const
connection
=
await
pool
.
getConnection
();
console
.
log
(
"
You are connected!
"
);
connection
.
release
();
// ปล่อยการเชื่อมต่อหลังใช้งาน
}
catch
(
err
)
{
console
.
error
(
"
Connection failed:
"
,
err
);
}
}
connectDatabase
();
// เรียกใช้งานฟังก์ชัน
module
.
exports
=
pool
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment