device location dropdaown menu
This commit is contained in:
42
pages/api/talas_v5/location_device.js
Normal file
42
pages/api/talas_v5/location_device.js
Normal file
@@ -0,0 +1,42 @@
|
||||
// pages/api/talas_v5/location_device.js
|
||||
// talas_v5 Datenbank -> location_device Tabelle enthält DAUZ Geräte
|
||||
|
||||
import mysql from "mysql";
|
||||
|
||||
const dbConfig = {
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.DB_NAME,
|
||||
port: process.env.DB_PORT,
|
||||
};
|
||||
console.log("my dbconfig: ", dbConfig);
|
||||
export default function handler(req, res) {
|
||||
const connection = mysql.createConnection(dbConfig);
|
||||
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Fehler beim Verbinden:", err.stack);
|
||||
res.status(500).json({ error: "Verbindungsfehler zur Datenbank" });
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Verbunden als ID", connection.threadId);
|
||||
//Fehler weil, existiertdie Tabelle auf localhost:3000 nicht
|
||||
connection.query(
|
||||
"SELECT idLD, iddevice, iddevice, name FROM location_device WHERE iddevice = 160",
|
||||
(error, results) => {
|
||||
if (error) {
|
||||
console.error("Fehler beim Abrufen der API", error);
|
||||
res.status(500).json({ error: "Fehler bei der Abfrage" });
|
||||
return;
|
||||
}
|
||||
|
||||
// Wichtig: Senden Sie die Antwort zurück
|
||||
res.status(200).json(results);
|
||||
|
||||
connection.end();
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user