# dbPoll (Server)

> Reads the answer of a `dbQuery` query, waiting for it if needed.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Server
- **Category**: Database
- **URL**: https://wiki.mymp.gg/en/dbPoll

## Syntax

```lua
table|false|nil, int, int|string dbPoll(any query, int timeout)
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `query` | `any` | The handle `dbQuery` returned. |
| `timeout` | `int` | How many milliseconds to wait: `0` does not wait, `-1` waits as long as it takes. |

## Returns

`nil` if the answer has not arrived yet. Otherwise, the rows (one table per row, its columns by name; a `NULL` column is left out), the number of affected rows and the last inserted id. If the query failed, `false`, the error code and the message. Once an answer is returned, the handle is freed.

## Example

```lua
local query = dbQuery(db, "SELECT money FROM players WHERE account = ?", accountId)
local rows, affected, lastId = dbPoll(query, -1)
if rows and rows[1] then
    print("money: " .. rows[1].money)
end
```

### Note

Waiting blocks the server until the answer arrives; prefer `0` inside a `callback`.

## See also

- [dbQuery (Server)](https://wiki.mymp.gg/en/dbQuery.md): Sends an SQL query whose answer is read later with dbPoll.
- [dbFree (Server)](https://wiki.mymp.gg/en/dbFree.md): Discards a dbQuery query whose answer will not be read.
