Modules/MTA-MySQL/mysql fetch assoc

From Multi Theft Auto: Wiki
Revision as of 18:05, 5 January 2011 by Alberto Alonso (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Package-x-generic.png This function is provided by the external module MTA-MySQL. You must install this module to use this function.

Returns an associative table containing the current row of the last executed query. You can call this function repeatedly to retreive all the result rows. When there aren't more rows in the result it returns nil. You can go to a specific row calling mysql_data_seek()

Syntax

table mysql_fetch_assoc ( MySQLResult result )

Required arguments

  • result: A valid MySQL result

Returns

An associative table with the current row

Example

Example 1: This example shows the name of all the registered accounts

local result = mysql_query(handler, "SELECT * FROM account") -- Execute the query
if (result) then
  while true do
    local row = mysql_fetch_assoc(result)
    if (not row) then break end

    outputDebugString(row["name"])
  end
  mysql_free_result(result) -- Free the result
end

See also