Jump to content

[MySQL RESULT]I NEED HELP ABOUT MySQL RESULT FUNCTION


Recommended Posts

when i try this code it's never insert datas into database pls help me...

 

)
-- root = getElementRoot()
addEventHandler("onPlayerLogin", root,
function(_, account)
    outputChatBox(getPlayerName(source).." Giriş yapti.", root) 
    local oyuncu = getPlayerName(source)
    local ip = getPlayerIP(source)
    local serial = getPlayerSerial(source)
    local username = getAccountName(account)
    local result = dbPoll( dbQuery( userdata_db, "SELECT * FROM masterdata WHERE username = ?", username ), -1 )
    if type(result) ~= 0 then
        outputChatBox("#afafaf[#f9a52fSA:MP#afafaf] #f9a52fVeritabanina bir veri eklenmedi.",root, 255, 255, 255, true )
    else
		dbQuery( userdata_db, "INSERT INTO masterdata VALUES (?,?,?,?,?)",username,serial,ip, '',oyuncu)
    end
end)

Console Log : 

Username = Asokanta

WARNING: mysql/serverside.lua:22: Bad argument @ 'dbQuery' [Expected
db-connection at argument 1, got nil]
WARNING: mysql/serverside.lua:22: Bad argument @ 'dbPoll' [Expected dbquery at argument 1, got boolean]

Username = deneme

WARNING: mysql/serverside.lua:22: Bad argument @ 'dbQuery' [Expected
db-connection at argument 1, got nil]
WARNING: mysql/serverside.lua:22: Bad argument @ 'dbPoll' [Expected dbquery at argument 1, got boolean]

I Fixed Here* It's giving only login logs but it still don't insert data in database when result isn't 0

New Console Log :

LOGIN: (Everyone, Console) Asokanta successfully logged in as 'Asokanta'

LOGIN: (Everyone) Asokanta successfully logged in as 'deneme'

Database Screenshot : 

88bfeeafede8424f92b4c658a67cd8d1.png

Edited by Asokanta
Link to comment

WARNING: mysql/serverside.lua:22: Bad argument @ 'dbQuery' [Expected
db-connection at argument 1, got nil]

 

It says that 'userdata_db' isn't a database connection, meaning you failed to connect to the database.

Link to comment

Because dbQuery returns a handle, with which you can get data from a table using dbPoll. It waits until you use it, so if you free it, it would work.

dbExec only executes query, therefore returns nothing.

Link to comment
local result, num_rows_affected = dbPoll(dbQuery(userdata_db,"SELECT * FROM masterdata WHERE username = ?",username),-1)
if num_rows_affected ~= 0 then
    outputChatBox("#afafaf[#f9a52fSA:MP#afafaf] #f9a52fVeritabanina bir veri eklenmedi.",root,255,255,255,true)
else
    dbExec(userdata_db,"INSERT INTO masterdata VALUES (?,?,?,?,?)",username,serial,ip,'',oyuncu)
end

 

  • Like 1
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...