Jump to content

Please help me in mysql


HireAmine

Recommended Posts

--local connection = exports.db:getConnection()
account = ""
player = ""

function writedata(query)
local connection = exports.db:getConnection()--I have another script that exports the connection
local result = dbPoll(query, 0)
if (#result > 0 ) then
 local up = dbQuery(connection, "UPDATE players SET money = ? WHERE account = ? ", getPlayerMoney(player), account)--Update player money if found result
 dbFree(up)
elseif (#result == 0 ) then
    local insert = dbQuery(connection, "INSERT INTO players (account, money) VALUES(?, ?) ", account, getPlayerMoney(player))--insert player money if found result
end
end

addEventHandler("onPlayerQuit", root, function(quitType, reason, responsibleElement)
    local connection = exports.db:getConnection()--I have another script that exports the connection
    player = source--reset the player element variable
    account = getPlayerAccount(source)--reset the account variable
    dbQuery(writedata, connection, "SELECT * FROM players ", source)
end)



function returnn(select)
    local connection = exports.db:getConnection()--I have another script that exports the connection
    local result = dbPoll(select, 0)
    for i, v in pairs(result) do
    if v.money then--check if there is a value
        setPlayerMoney(player, v.money)--set the player money
    end
    end
end


addEventHandler("onPlayerLogin", root, function(_, acc)
    local connection = exports.db:getConnection()--I have another script that exports the connection
    account = acc--reset the account variable
    player = source--reset the player element variable
    local select = dbQuery(returnn, connection, "SELECT * FROM players")
end)

 

The error is the console said that: Bad Agrument @ 'getPlayerMoney' [expected player at agrument ]

Link to comment
--local connection = exports.db:getConnection()
account = ""
player = nil

function writedata(query)
 if not player then return end
local connection = exports.db:getConnection()--I have another script that exports the connection
local result = dbPoll(query, 0)
if (#result > 0 ) then
 local up = dbQuery(connection, "UPDATE players SET money = ? WHERE account = ? ", getPlayerMoney(player), account)--Update player money if found result
 dbFree(up)
elseif (#result == 0 ) then
    local insert = dbQuery(connection, "INSERT INTO players (account, money) VALUES(?, ?) ", account, getPlayerMoney(player))--insert player money if found result
end
end

addEventHandler("onPlayerQuit", root, function(quitType, reason, responsibleElement)
    local connection = exports.db:getConnection()--I have another script that exports the connection
    player = source --reset the player element variable
	if player then
     account = getPlayerAccount(source)--reset the account variable
     dbQuery(writedata, connection, "SELECT * FROM players ", source)
	end
end)



function returnn(select)
    local connection = exports.db:getConnection()--I have another script that exports the connection
    local result = dbPoll(select, 0)
    for i, v in pairs(result) do
    if v.money then--check if there is a value
        setPlayerMoney(player, v.money)--set the player money
    end
    end
end


addEventHandler("onPlayerLogin", root, function(_, acc)
    local connection = exports.db:getConnection()--I have another script that exports the connection
    account = acc--reset the account variable
    player = source--reset the player element variable
    local select = dbQuery(returnn, connection, "SELECT * FROM players")
end)

test this

Link to comment
On 31/08/2022 at 14:42, HireAmine said:
--local connection = exports.db:getConnection()
account = ""
player = ""

function writedata(query)
local connection = exports.db:getConnection()--I have another script that exports the connection
local result = dbPoll(query, 0)
if (#result > 0 ) then
 local up = dbQuery(connection, "UPDATE players SET money = ? WHERE account = ? ", getPlayerMoney(player), account)--Update player money if found result
 dbFree(up)
elseif (#result == 0 ) then
    local insert = dbQuery(connection, "INSERT INTO players (account, money) VALUES(?, ?) ", account, getPlayerMoney(player))--insert player money if found result
end
end

addEventHandler("onPlayerQuit", root, function(quitType, reason, responsibleElement)
    local connection = exports.db:getConnection()--I have another script that exports the connection
    player = source--reset the player element variable
    account = getPlayerAccount(source)--reset the account variable
    dbQuery(writedata, connection, "SELECT * FROM players ", source)
end)



function returnn(select)
    local connection = exports.db:getConnection()--I have another script that exports the connection
    local result = dbPoll(select, 0)
    for i, v in pairs(result) do
    if v.money then--check if there is a value
        setPlayerMoney(player, v.money)--set the player money
    end
    end
end


addEventHandler("onPlayerLogin", root, function(_, acc)
    local connection = exports.db:getConnection()--I have another script that exports the connection
    account = acc--reset the account variable
    player = source--reset the player element variable
    local select = dbQuery(returnn, connection, "SELECT * FROM players")
end)

 

The error is the console said that: Bad Agrument @ 'getPlayerMoney' [expected player at agrument ]

local connection = exports.db:getConnection()

addEventHandler ("onPlayerQuit", root, function ()
	local accName = getAccountName(getPlayerAccount(source))
	local result = dbPoll(dbQuery(connection, "SELECT * FROM players WHERE account = ?", accName), -1)
	if #result > 0 then
		dbExec (connection, "INSERT INTO players (account, money) VALUES(?, ?)", accName, getPlayerMoney(source))
	else
		dbExec (connection, "UPDATE players SET money = ? WHERE account = ?", getPlayerMoney(source), accName)
	end
end)


addEventHandler("onPlayerLogin", root, function(_, account)
	local accName = getAccountName(account)
	local result = dbPoll(dbQuery(connection, "SELECT * FROM players WHERE account = ?", accName), -1)
	if #result > 0 then
		setPlayerMoney (source, result[1]["money"]
	end
end)

 

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...