Posts: 5
Threads: 2
Joined: Aug 2018
Reputation:
0
So i am using SA-MP-MySQL R41-4, and when a player registers a new account, a query for adding a new row in the table of users is made by mysql_tquery function. Recently i added a system of inventory on my server, and now i need 2 queries for creating a row in the users table and in the inventories table to be executed at once, but it's impossible to do that in mysql_tquery function (i've tried separating them by ';', i get syntax errors in the mysql log). The only idea that i've got so far is to make "chain" of tquery'ies so that it first inserts a new row into talbe `users`, then in the callback of that tquery it inserts a new row into `inventories` table etc., but that's ultra ugly code, and there must be a much better way to solve my problem. So what can i do?
Posts: 156
Threads: 0
Joined: Jun 2016
What you did was right. Alternatively,
you could try MySQL stacked queries using the delimeter ";", so you can do multiple queries in one function call.
If you're using MySQLi checkout multi_query function.
Posts: 5
Threads: 2
Joined: Aug 2018
Reputation:
0
The problem with 2 separate threaded queries is that i need to SELECT the data that i just inserted (inside of the callback of mysql_tquery), because i set default values (e.g. level: 1) in mysql table rather than hardcode it in the gamemode. I guess there is no cleaner way to do the thing other than hardcode default values for new-registered players and also keep default values in mysql tables? In that case all registered players' data is properly inserted into database and the same data is set on the server itself, and when a player logs in there must be 2 threaded queries (for `inventories` and for `players` tables) on whose callbacks all rows are inserted in appropriate variables on server, right?