Closed thomas-pns closed 3 years ago
In your query1
's onSuccess
callback, the first argument (q
) is the query1
object itself, and the second argument (data
) is a table containing all returned rows (so in your case, all the rows that matched the selection query):
Query.onSuccess( q, data ) -- Called when the query is successful, [Table] data is the data the query returned.
From what I remember, the table within data
should look something like this (if it selected only 1 row, and where example
& abc
are column names):
{
{
["example"] = "xyz",
["abc"] = 123
}
}
Therefore to get the data, you should do data[1]["example"]
, where 1
is the row number and example
is the name of the column.
Hello , i have a problem or no the mysqloo works very well but I do not understand a result of query "SELECT * FROM user WHERE steamID = '545874984196841'"
Its my code (server.lua) :
require ("mysqloo")
local DATABASE_HOST = "127.0.0.1" local DATABASE_PORT = 3306 local DATABASE_NAME = "DarkRP" local DATABASE_USERNAME = "thomas" local DATABASE_PASSWORD = "*****"
databaseObject = mysqloo.connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, DATABASE_PORT)
databaseObject.onConnected = function() print("Database linked!") end databaseObject.onConnectionFailed = function() print("Failed to connect to the database.") end databaseObject:connect()
function testsql(ply) print("the function testsqql() is exec because the player "..ply:Nick().." spawn") local query1 = databaseObject:query("SELECT * FROM user WHERE steamID = '545874984196841'") query1.onSuccess = function(q, data) print("query1 succes !") print(q) ←------------- return : Query 0x228de580 print(data) ←----------------- return : table: 0xf02f3450 print(q:getData()[1]) ←----------- return : table: 0xf02f3478 end query1.onError = function() print("query1 error !") end query1:start() end
hook.Add( "PlayerSpawn", "some_unique_name", testsql )