View Full Version : Database

05-26-2014, 02:26 PM
Hello , i checked the LuaFunctions in eluna and only have :

CharDBQuery -- TrinityCore
AuthDBQuery -- TrinityCore
WorldDBQuery -- TrinityCore

But i have one db called "TESTE" and i need to select an table from this. How i can do this in Eluna ?

I searched in google and found this :

require "luasql.mysql"
env = assert (luasql.mysql())
con = asset (env:connect"TESTE")

but use "require" it will work or i cant do this ?

Lightning Blade
05-26-2014, 02:51 PM
What does your TESTE db contain ?

05-26-2014, 03:04 PM
Actually have one table with vote points , but i cant move this table to other DB

05-26-2014, 03:34 PM
are you just trying to gather data from entries in a custom db? like this?
'zones' is a table within the custom db 'guild_warz'.

local Gwsql = WorldDBQuery("SELECT * FROM guild_warz.zones;");

GWARZ[Gwsql:GetUInt32(0)] = {
entry = Gwsql:GetUInt32(0),
map_id = Gwsql:GetUInt32(1),
area_id = Gwsql:GetUInt32(2),
zone_id = Gwsql:GetUInt32(3),
guild_name = Gwsql:GetString(4),
team = Gwsql:GetUInt32(5),
x = Gwsql:GetFloat(6),
y = Gwsql:GetFloat(7),
z = Gwsql:GetFloat(8),
farm_count = Gwsql:GetUInt32(9),
barrack_count = Gwsql:GetUInt32(10),
hall_count = Gwsql:GetUInt32(11),
pig_count = Gwsql:GetUInt32(12),
guard_count = Gwsql:GetUInt32(13),
flag_id = Gwsql:GetUInt32(14),
spawn_time = Gwsql:GetUInt32(15)
until not Gwsql:NextRow()

- - - Updated - - -

you would do something like this then:

local DBvote = WorldDBQuery("SELECT 'votes' FROM TESTE;"); -- locally stored
local votes = DBvote:GetUInt32(0) -- 0 being the first in the sequence of 'SELECT' -- locally stored
ACCT[player:GetAccountId()].Vote = votes -- Globally accessed value Via the Key

ofc I am assuming this will not be for 1 player so you would need to create a table assigned to the character. do a script for on login then assign the value via table to the account ID/Name.
take a look at these pointers I showed on your simple premium system creating a table that is keyed to the players account ID


ACCT[player:GetAccountId()] .Vote
^ the key is the players account ID ^

05-26-2014, 04:20 PM
with more info like maybe a copy of your TESTE db then I could setup an 'on login' script that will table the votes for each character when they login for you.

05-26-2014, 05:33 PM
slp13 thx but the problem are TESTE database are not in World database
i have 4 data

05-26-2014, 05:44 PM
I searched in google and found this :

require "luasql.mysql"
env = assert (luasql.mysql())
con = asset (env:connect"TESTE")

but use "require" it will work or i cant do this ?

That requires an external module.
Unfortunately you will probably need to compile it yourself.

The solution provided by slp13at420 has been working on arcemu and, according to what he has been using it with his scripts, it seems to work on Eluna.

slp13 thx but the problem are TESTE database are not in World database
i have 4 data

local Gwsql = WorldDBQuery("SELECT * FROM guild_warz.zones;");
Notice that this is the sytanx for accessing another DB, and the zones table in it.

05-26-2014, 06:01 PM
understand , i will try and post the results soon

05-26-2014, 08:39 PM
Why not just put the vote points table in your auth, characters or world database and let your website connect to that? That way, you can use Eluna and PHP to connect to both. Would be the most viable solution, rather than wasting time trying to run a module that isn't embedded into Eluna.

05-26-2014, 08:57 PM
You just need to supply the database name before the table name, like Rochet mentioned. Instead of Table, you would do Database.Table. Easy as that! :P

05-26-2014, 10:42 PM
if you provide a copy of or s.s. of the TESTE.table then I could just write you a simple on-logon event script that will use tables. much faster than querying over n over for the same value.

it would look something like this . but with proper addressing of data location..:

function Player_Vote_Table(event, player)

local Web = WorldDBQuery("SELECT votes FROM TESTE.TABEL_NAME_HERE WHERE `acct_id` = '"..player:GetAccountId().."';"); -- acct_id or what ever the name is for the acctID column.
local Act = WorldDBQuery("SELECT username FROM auth.account WHERE `id` = '"..player:GetAccountId().."';"); -- yes this WorldDBQuery works flawlessly as long as you know the location of the data you are reaching for. thankyou Rochet2

ACCT={} -- allocates the table
ACCT[player:GetAccountId()] = {
Name = Act:GetString(0),
Votes = Web:GetUInt32(0)
};-- populates the table locations with datumn using accountID as a key to locate the data and to store the data

-- examples of how its can be used
player:SendBroadcastMessage("Greetings "..ACCT[player:GetAccountId()].Name..", You have voted "..ACCT[player:GetAccountId()].Votes.." times.")
player:SendBroadcastMessage("try to reach "..(ACCT[player:GetAccountId()].Votes*2).." votes. hahaha")

RegisterPlayerEvent(3, Player_Vote_Table)

the 'acct_id' should be changed to the column name your website uses to store the account id .
I also have custom db's:
characters4 -- so you can have the same char name on all worlds.
guild_warz -- used only with world1
world1 -- inst80
world2 -- blizz-like
world3 -- 255max
world4 -- test
world5 -- clean

05-27-2014, 12:47 PM
slp thx , work now :D i used SELECT Votepoints FROM TESTE.account where id = "..plr:GetAccountId().."
and one GetUInt32 :D thx

05-27-2014, 11:44 PM

wooohoooooooooo right on
now you can use that stored value in other scripts or store more account data to be used in other scripts since its global.
I kinda wrote that one to show some examples of how I use WorldDBQuery for everything and it works flawlessly for querying.
you can select more than just 1 data .
you can use this way to target all the data of a specific db table and assign what you want:

Act = WorldDBQuery("SELECT * FROM auth.account WHERE 'id' = '"..plr:GetAccountId().."';")
TABLE[plr:GetAccountId()] = {
Id = Act:GetUInt32(0),
Name = Act:GetString(1),
Ip = Act:GetString(13),
Email = Act:GetString(11)

or you can do this way and target only what you want to use:

Act=WordDBQuery("SELECT id, username FROM auth.account WHERE 'id' = '"..plr:GetAccountId().."';")

TABLE[plr:GetAccountId()] = {
Id = Act:GetUInt32(0),
Name = Act:GetString(1)

I use the second route myself except for certain needs like in guild warz location table. it grabs all entries and columns but also uses all the data. I prefer to just pinpoint what I need so I don't load a bunch of unused data .. may be some time consumption dunno lol