-
Notifications
You must be signed in to change notification settings - Fork 1
MySQL Module ConnectionClass execute
DizzasTeR edited this page Nov 2, 2020
·
5 revisions
Executes a mysql query and returns the number of affected rows
int MySQLConnection:execute(string query [, ...optionalParameters])
int MySQLConnection:execute(function callback, string query [, ...optionalParameters])- 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:query(function(result)
print("OK")
end, "SELECT * FROM test_table WHERE name LIKE ?", {"%dizz%"})