MZ Need Help Writing Code or Plugin

Hi there, I am working on my game from long time and its almost completed, but what i need is to connect my game with xampp - mysql to make it leadship , level , board on website, currently i am using local host
i can make the database and can write php code mysql queries, i just dont know how to make plugin or script in java to fetch
information from game client. all i just need explaining couple of examples writting it.

1) i want to make login system for my game
2) then fetch gold and level of player to fetch to mysql database to make leadership bord

currently i am using
host : localhost,
user : root,
password : "",
database: "wisepot"

code : i m using :

// Load the mysql package
var mysql_package = require('mysql');

var connection_data = mysql_package.createConnection({
host: "localhost",
user: "root",
password: "",
database: "shop"
});

connection_data.connect(function(err) {
console.log("Connected to XAMPP Server!");
});

i try to use code and try to connect with database but getting error with js file or plugin file
but it works with the php file correctly

i jst want some 1 write me one js file or plugin file - that connect database and i can write some queries in that to fetch gold and level values
The problem is this line
Code:
var mysql_package = require('mysql');

"require" is a keyword for nodejs to import modules but this is not available in the context that RPGMaker runs normally.

If you want to use node modules here's a thread on how to do that in RPGMaker MV, I haven't tried it myself but it should work with RMMZ too: https://forums.rpgmakerweb.com/inde...aker-mv-project-tutorial.137598/#post-1195210
I recommend making a backend, e.g., NodeJS or Python Flask. Both are easy to understand and implement.

Hosting a backend, however, is more difficult. You can use services such as https://www.netlify.com/ or https://replit.com/site/hosting that take over most tasks.

If you don't know, a backend is a bridge to connect your game with your database. Your game will send REST requests to your backend; hence, you don't need any npm module because you can use "XMLHttpRequest". Your backend will read from and write to your database.
thank you so much both of you for sending me some tutorial
i used the first npm install and now it works finally i got messge in console
database connected 🙂
thanks its works for me
Great, glad it is working for you! Just keep in mind as Aerosys says, you will need a hosting solution for your database once you release your game, local host will work fine for testing though. Cheers!
yes i know 😛 but its really good to know finally can connect to database now i m working on things to get in to game variables and then transfer them to other variables to send to datbase😛
Oh for sure, if it works it works. Im not one to talk since Im using a google spreedsheet as my database for highscores lol

Original thread: https://forums.rpgmakerweb.com/threads/need-help-writing-code-or-plugin.156606/