mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-01 22:21:48 +00:00
92 lines
1.7 KiB
Plaintext
92 lines
1.7 KiB
Plaintext
---
|
|
title: query
|
|
---
|
|
|
|
import { Tab, Tabs } from 'nextra-theme-docs';
|
|
|
|
When selecting data, returns all matching rows and columns; otherwise, returns data like insertId, affectedRows, etc.
|
|
|
|
## Promise
|
|
|
|
<Tabs items={['Lua', 'JS']}>
|
|
<Tab>
|
|
|
|
```lua
|
|
local response = MySQL.query.await('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', {
|
|
identifier
|
|
})
|
|
|
|
if response then
|
|
for i = 1, #response do
|
|
local row = response[i]
|
|
print(row.firstname, row.lastname)
|
|
end
|
|
end
|
|
```
|
|
|
|
</Tab>
|
|
<Tab>
|
|
|
|
```js
|
|
const response = await MySQL.query('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', [
|
|
identifier
|
|
])
|
|
|
|
if (response) {
|
|
response.forEach((row) => {
|
|
console.log(row.identifier, row.firstname, row.lastname)
|
|
})
|
|
}
|
|
```
|
|
|
|
</Tab>
|
|
</Tabs>
|
|
|
|
**Aliases**
|
|
|
|
- `MySQL.Sync.fetchAll`
|
|
- `exports.ghmattimysql.execute`
|
|
- `exports.oxmysql.query_async`
|
|
|
|
## Callback
|
|
|
|
<Tabs items={['Lua', 'JS']}>
|
|
<Tab>
|
|
|
|
```lua
|
|
MySQL.query('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', {
|
|
identifier
|
|
}, function(response)
|
|
if response then
|
|
for i = 1, #response do
|
|
local row = response[i]
|
|
print(row.firstname, row.lastname)
|
|
end
|
|
end
|
|
end)
|
|
```
|
|
|
|
</Tab>
|
|
<Tab>
|
|
|
|
```js
|
|
MySQL.query('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', [
|
|
identifier
|
|
], (response) => {
|
|
if (response) {
|
|
response.forEach((row) => {
|
|
console.log(row.firstname, row.lastname)
|
|
})
|
|
}
|
|
})
|
|
```
|
|
|
|
</Tab>
|
|
</Tabs>
|
|
|
|
**Aliases**
|
|
|
|
- `MySQL.Async.fetchAll`
|
|
- `exports.ghmattimysql.execute`
|
|
- `exports.oxmysql.query`
|