Skip to content

MySQL Module ConnectionClass query

DizzasTeR edited this page Jan 30, 2021 · 3 revisions

MySQL Connection

query

Executes a mysql query and returns the result as a table

int MySQLConnection:query([function callback, ] string query [, ...optionalParameters])

Parameters

  • 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)

Returns

table - Query result. May be an empty table if no matching results. nil if the query failed

Example

if MySQLTests.query then
        local result = connection:query("SELECT * FROM test_table WHERE name = ?", {"dizzo"})
        print("Got #"..#result.." results")
        if #result > 0 then
            local row = result[1]
            print("["..type(row.id).."] "..row.id.." => ["..type(row.name).."] "..row.name)
        end
    end

Clone this wiki locally