Database connection, String error = tmysql.initialize( String hostname, String username, String password, String database, Number port, String unixSocketPath, Number ClientFlags )
String escaped = Database:Escape( String stuff )
Table connections = tmysql.GetTable()
Database:Connect() -- Starts and connects the database for tmysql.Create
Database:Option(MYSQL_OPT_ENUM, String option) -- Sets a mysql_option for the connection. Use with tmysql.Create then call Connect() after you set the options you want.
Database:Disconnect() -- Ends the connection for this database and calls all pending callbacks immediately. Any method calls to this database, from now on, will error.
Database:Query( String query, Function callback, Object anything, Boolean ColumnNumbers )
function callback( Table results )
Results {
[1] = {
status = true/false,
error = the error string,
affected = number of rows affected by the query,
lastid = the index of the last row inserted by the query,
time = how long it took to complete,
data = {
{
somefield = "some shit",
otherfield = "other shit",
}
},
},
}
If status is false, data, affected, and lastid will be nil
local function onPlayerCompleted( ply, results )
print( "Query for player completed", ply )
PrintTable( results[1].data )
end
Database:Query( "SELECT * FROM some_table", onPlayerCompleted, Player(1) )
local function onCompleted( results )
print( "Query completed" )
PrintTable( results[1].data )
end
Database:Query( "SELECT * FROM some_table", onCompleted )
function GM:OurMySQLCallback( results )
print( results )
end
Database:Query( "SELECT * FROM some_table", GAMEMODE.OurMySQLCallback, GAMEMODE ) -- Call the gamemode function
local Database, error = tmysql.Connect("localhost", "root", "root", "test", 3306, nil, CLIENT_MULTI_STATEMENTS)
local function onCompleted( results )
print( "Query completed" )
PrintTable( results )
print("1+5 = ", results[2].data["1+5"])
end
Database:Query( "SELECT * FROM test; SELECT 1+5;", onCompleted )
local Database, error = tmysql.Create("localhost", "root", "root", "test", 3306, nil, CLIENT_MULTI_STATEMENTS)
Database:Option(MYSQL_SET_CLIENT_IP, "192.168.1.123")
local status, error = Database:Connect()