Jump to content

Best way to use MySQL queries


Recommended Posts

I'm currently working on my own roleplay server and I have created serveral resources that all connect to one MySQL database with serveral tables that contain all the userdata. When I need the data ingame in a resource I load it from the MySQL database and store it in an array/table in my script This is usually when a new player logs into the server. When the user quits the server his data is saved again in the MySQL database.

The problem is I somtimes need the same information from the database in multiple resources at the same time. Which means that if I load the data from the MySQL database into both resources and its changed in one resource, it's not automatically changed in the other resource.

I figured my way might not be the best way to use MySQL queries. I know using setElementData() to share data across resources is a possibility but means more lag. I figured maybe instead of loading the data into an array/table just using queries all the time to load and save it from/in the MySQL database is an option, but maybe you guys have a better solution?

Link to comment

To transfer data from your database you can create the 'get' and 'set' functions which are a must in big projects. I'm also using this method, you can just create a resource that actually does this;

-- onResourceStart 
-- execute your query 
-- load the queryData into an array. 
  
-- getPlayerData  
-- return the value from the array 
  
-- setPlayer data 
-- edit the value inside the array 

if you need some playerData in your vehicle system, you can just request it using the getPlayerData() in your other resource. on that way you don't have to use a million queries! :)

Link to comment
if you need some playerData in your vehicle system, you can just request it using the getPlayerData() in your other resource. on that way you don't have to use a million queries! :)

So if I understand you correctly you suggest that I create the functions in a new resource specificaly designed to load my queries, and export them to access them in other resources?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...