You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DizzasTeR edited this page Jan 30, 2021
·
5 revisions
MySQL Connection
execute
Executes a mysql query and returns the number of affected rows
int MySQLConnection:execute([function callback, ] string query [, ...optionalParameters])
Parameters
optionalstring function — Function to call with the number of affected rows (OPTIONAL)
string query — The query to execute
optional optionalParameters — Forward any extra parameters with the query (Used for prepared statements)
Returns
int - Number of affected rows if successful, false if the query failed
Example #1
localresult=connection:execute("UPDATE test_table SET name = ? WHERE id = ?", {"dizzo", 1})
ifresult~=falsethenprint("Affected rows execution result 1: "..tostring(result))
result=connection:execute("UPDATE test_table SET name = ? WHERE id = ?", {[2] =2, [1] ="epic"})
print("Affected rows execution result 2: "..tostring(result))
-- Simple statement (Works for query and insert as well)result=connection:execute("UPDATE test_table SET name = 'topkek' WHERE id = 2")
print("Affected rows execution result 3: "..tostring(result))
end
Example #2
-- callback versionsconnection:execute(function(result)
print("OK")
end, "UPDATE test_table SET score = 100 WHERE name LIKE ?", {"%dizz%"})