2024-09-17 14:36:35 +00:00
|
|
|
import mysql from "mysql2";
|
|
|
|
|
|
|
|
// MySQL connection setup (you can move this to a separate config file if needed)
|
|
|
|
const db = mysql.createConnection({
|
|
|
|
host: "db-mysql-nyc1-99306-do-user-12431193-0.b.db.ondigitalocean.com",
|
|
|
|
user: "doadmin",
|
|
|
|
password: "AVNS_EPHqPilzmVjZfm8GH4G",
|
|
|
|
database: "defaultdb",
|
|
|
|
port: "25060",
|
2024-09-17 15:14:56 +00:00
|
|
|
connectTimeout: 20000, // 20 seconds
|
2024-09-17 14:36:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Connect to MySQL database
|
|
|
|
db.connect((err) => {
|
|
|
|
if (err) {
|
|
|
|
console.error("Database connection failed: " + err.stack);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log("Connected to the MYSQL database.");
|
|
|
|
});
|
|
|
|
|
|
|
|
// Controller function
|
|
|
|
export const searchMySQL = (req, res) => {
|
|
|
|
const q = "SELECT * FROM client_info";
|
|
|
|
db.query(q, (err, data) => {
|
|
|
|
if (err) {
|
|
|
|
console.log(err);
|
|
|
|
return res.status(500).json({ error: "Database query failed" });
|
|
|
|
}
|
|
|
|
return res.json(data);
|
|
|
|
});
|
|
|
|
};
|