mirror of
https://github.com/Alvin-Zilverstand/school.git
synced 2026-04-18 02:57:02 +02:00
:3
This commit is contained in:
29
projects/challenge 8/pokedex/v2/convert-images.js
Normal file
29
projects/challenge 8/pokedex/v2/convert-images.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const mysql = require("mysql");
|
||||
|
||||
const connection = mysql.createConnection({
|
||||
host: "localhost", // Ensure this points to your local database
|
||||
user: "root",
|
||||
password: "",
|
||||
database: "pokedex1",
|
||||
port: 3306,
|
||||
});
|
||||
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Error connecting to the database:", err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log("Connected to the local database.");
|
||||
|
||||
const query = "UPDATE pokemon SET image_url = REPLACE(image_url, '.png', '.webp')";
|
||||
console.log("Executing query:", query);
|
||||
|
||||
connection.query(query, (error, results) => {
|
||||
if (error) {
|
||||
console.error("Error updating image URLs:", error.message);
|
||||
} else {
|
||||
console.log("Image URLs updated successfully. Rows affected:", results.affectedRows);
|
||||
}
|
||||
connection.end();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user