Jump to content

[MySQL] Databse Load System - Need Help...


xiti

Recommended Posts

Hello everyone.

I want help from someone with my load data function. I wanna wright a userpanel and without this i cant make this. I work on this some time and i cant solwe this problem, i try a lot of combination and i dont see a different in this code and idk why this dont work. Please help with this!

here is my Load system:

function loadPlayerData (thePlayer,datatype) 
    if (thePlayer) and (datatype) then 
        local guest = getElementData(thePlayer, "loggedin") 
        if not (guest == false) then 
            local account = getElementData(thePlayer, "account") 
            local connect = dbConnect( "mysql", "dbname=localhost;host=localhost", "admin", "admin", "share=1" ) 
            local findQuery = dbQuery( connect,"SELECT '"..datatype.."' FROM smf_sdmembers WHERE passwd='"..account.."'", datatype, account) 
            if (findQuery) then 
                outputChatBox(""..tostring(findQuery).."") 
                local result, numrows, errmsg = dbPoll ( findQuery, -1 ) 
                    if numrows > 0 then 
                        outputChatBox(""..result.."") 
                        return result 
                    else 
                        return 0 
                    end 
            else 
                outputDebugString("Failed to get "..datatype.." for player "..getPlayerName(thePlayer).." @ findQuery") 
            end 
        else 
            outputDebugString("Player not logged "..getPlayerName(thePlayer)..".") 
        end 
    else 
        outputDebugString("Bad arguments loadPlayerData.") 
    end 
end 

Thank for help! Regards, Xiti :D

Link to comment

function loadPlayerData ( uPed, cData ) 
    -- check if data have been passed 
    if ( uPed and cData and type ( cData ) == 'string' ) then 
    -- exists element data 'loggedin' ? 
        if ( getElementData ( uPed, 'loggedin' ) ) then  
            local cAccount = getElementData ( uPed, 'account' ) 
            -- are u right that dbname is localhost? 
            local vConnect = dbConnect ( 'mysql', 'dbname = localhost ; host = localhost', 'admin', 'admin', 'share = 1' ) 
            local vQuery   = dbQuery ( vConnect, 'SELECT `?` FROM smf_sdmembers WHERE passwd = `?`', cData, cAccount ) 
            if ( vQuery ) then 
                outputChatBox ( tostring ( vQuery ) ) 
                local vResult, iRow, error = dbPoll ( vQuery, -1 ) 
                if ( iRow > 0 ) then 
                    outputChatBox ( tostring ( vResult ) ) 
                    return vResult 
                else 
                    return false 
                end 
            else 
                outputDebugString ( 'Failed to get ' .. cData .. ' for player ' .. getPlayerName ( uPed ) .. ' @ ' .. error ) 
            end 
        else 
            outputDebugString ( 'Player not logged in: ' .. getPlayerName ( uPed ) ) 
        end 
    else 
        outputDebugString ( 'Bad argument @ loadPlayerData' ) 
    end 
end 

Check comments.

Link to comment

Thanks Jayz but this not work now i dont know why, i try get a value from column exp and this still dont work. When i try get this the debugscript say me: dbPoll failed; Unknown column "exp" in "filed list". Someone help me? Thanks

Here is a code which i try get this from database.

loadPlayerData(thePlayer,"exp") 

Link to comment

On 100% the column exp is in database... I check this again... Maybe problem is in '?' becouse when i try get this then call me that column '"exp"' not exsit not 'exp' becouse i have function with "" (loadPlayerData(thePlayer,"exp"). This is only sugestion.

Link to comment
Note: Connecting and disconnecting many times can have a performance impact on the server. For optimal performance it is recommended that you use dbConnect only once when the resource starts, and share the connection element with the whole script.

You should only connect when the resource starts, not every time you want to retrieve data.

Try this:

addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        connect = dbConnect ( "mysql", "dbname=localhost;host=localhost", "admin", "admin", "share=1" ) 
    end 
) 
  
function loadPlayerData ( thePlayer, datatype ) 
    if ( connect ) and ( thePlayer) and ( datatype ) then 
        local guest = getElementData ( thePlayer, "loggedin" ) 
        if ( not guest == false ) then 
            local account = getElementData ( thePlayer, "account" ) 
            local findQuery = dbQuery ( connect, "SELECT `".. datatype .."` FROM smf_sdmembers WHERE passwd = '".. account .."'" ) 
            if ( findQuery ) then 
                outputChatBox ( "".. tostring ( findQuery ).."" ) 
                local result, numrows, errmsg = dbPoll ( findQuery, - 1 ) 
                if ( numrows > 0 ) then 
                    outputChatBox ( "".. result [ 1 ] [ datatype ].."") 
                    return result [ 1 ] [ datatype ] 
                else 
                    return 0 
                end 
            else 
                outputDebugString ( "Failed to get ".. datatype .." for player ".. getPlayerName ( thePlayer ) .." @ findQuery" ) 
            end 
        else 
            outputDebugString ( "Player not logged ".. getPlayerName ( thePlayer ) .."." ) 
        end 
    else 
        outputDebugString ( "Bad arguments loadPlayerData." ) 
    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...