Execute

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

Example

Async

exports.oxmysql:execute('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)
Sync
CreateThread(function()
    local result = exports.oxmysql:executeSync('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)

Async

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

Back to top