Files
overextended.github.io/docs/oxmysql/Usage/query.md
T
Linden 6bead3ca32 Consistent indentation and remove some files
Mixing tabs and spaces when embedding Lua can easily break MDX syntax.
2022-04-29 15:39:04 +10:00

1.4 KiB

Query

Generic function that can be utilised for any query.
When selecting data it will return all matching rows and columns, otherwise it will return field data such as insertid, affectedRows, etc.

Lua

Callback

-- Alias: exports.oxmysql:query
-- Alias: MySQL.Async.query

MySQL.query('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
    if result then
        for _, v in pairs(result) do
            print(v.identifier, v.firstname, v.lastname)
        end
    end
end)

Promise

-- Alias: exports.oxmysql:query_async
-- Alias: MySQL.Sync.query

CreateThread(function()
    local result = MySQL.query.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
    if result then
        for _, v in pairs(result) do
            print(v.identifier, v.firstname, v.lastname)
        end
    end
end)

JavaScript

Callback

exports.oxmysql.query('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
  if (result) {
    result.forEach((v) => {
      console.log(v.identifier, v.firstname, v.lastname)
    })
  }
})

Promise

(async () => {
  const result = await exports.oxmysql.query_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
  if (result) {
    result.forEach((v) => {
      console.log(v.identifier, v.firstname, v.lastname)
    })
  }
})()