-
Notifications
You must be signed in to change notification settings - Fork 1
MySQL Module ConnectionClass execute
DizzasTeR edited this page Jan 30, 2021
·
5 revisions
Executes a mysql query and returns the number of affected rows
int MySQLConnection:execute([function callback, ] string query [, ...optionalParameters])
- optional string 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)
int - Number of affected rows if successful, false if the query failed
local result = connection:execute("UPDATE test_table SET name = ? WHERE id = ?", {"dizzo", 1})
if result ~= false then
print("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
-- callback versions
connection:execute(function(result)
print("OK")
end, "UPDATE test_table SET score = 100 WHERE name LIKE ?", {"%dizz%"})