-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetchCartData.js
33 lines (27 loc) · 907 Bytes
/
fetchCartData.js
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
const mysql = require('mysql');
function fetchCartData(callback) {
const dbConfig = {
host: 'localhost',
user: 'root',
password: 'Yas@2004',
database: 'autocare'
};
const connection = mysql.createConnection(dbConfig);
connection.connect((err) => {
if (err) {
console.error('Error connecting to MySQL database:', err);
return callback(err, null);
}
console.log('Connected to MySQL database');
const sql = 'SELECT * FROM cart';
connection.query(sql, (err, rows) => {
connection.end(); // Close the connection
if (err) {
console.error('Error executing MySQL query:', err);
return callback(err, null);
}
callback(null, rows);
});
});
}
module.exports = fetchCartData;