1. -- LuaDirector MySQL demo
  2.  
  3. mysql = require "luasql.mysql"
  4.  
  5. ----------------------------------------
  6. -- Returns either the query result as list of propLists,
  7. -- or an error string
  8. ----------------------------------------
  9. on.mysql_query = function (sql)
  10.   local env = mysql.mysql()
  11.   local conn,err = env:connect('LuaDirectorTest', 'root', '<password>')
  12.   if err~=nil then
  13.     env:close()
  14.     return err
  15.   end
  16.   local cursor,err = conn:execute(sql)
  17.   if err~=nil then
  18.     conn:close()
  19.     env:close()
  20.     return err
  21.   else
  22.     local res = {}
  23.     local row = cursor:fetch ({}, "a")
  24.     while row~=nil do
  25.       res[#res+1] = row
  26.       row = cursor:fetch ({}, "a")
  27.     end
  28.     cursor:close()
  29.     conn:close()
  30.     env:close()
  31.     return res
  32.   end
  33. end
  34.  
[raw code]