Jump to content

MYSQL Select seems like to make problems


Maurize

Recommended Posts

Hello Ladies and Gentleman,

I'm tying to create a function which allows me to get fields from my mysql table.

What I've done so far:

  
local db = dbConnect("mysql", "host=localhost;dbname=mtasa", "root", ""); 
function getData(player, db_table, db_row) 
    dbQuery(function(e) 
        local result = dbPoll(e, 0); 
        return result[db_row]; 
    end, db, "SELECT "..db_row.." FROM "..db_table.." WHERE username = '"..getPlayerName(player).."' LIMIT 1"); 
end 

This gives an error if I try to outputChatBox the result.

Maybe someone can help me up with this.

Edited by Guest
Link to post

Yeah I thought the same but this didn't solved my problem.

If I try to outputChatBox the result it gives an error -> Expected string

Current function:

local db = dbConnect("mysql", "host=localhost;dbname=mtasa", "root", ""); 
function getData(player, db_table, db_row) 
    dbQuery(function(e) 
        local r = dbPoll(e, 0); 
        return r[1][db_row]; 
    end, db, "SELECT "..db_row.." FROM "..db_table.." WHERE username = '"..getPlayerName(player).."' LIMIT 1"); 
end 

I think the async makes problems.

If I do the query directly in database it works like charm but not in .lua.

Link to post

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