mysql.one
mysql.one
Function
Execute a query and return a single row of results.
Syntax
mysql(dsn).query(sql).one()
Parameters
No parameters.
Return value
| Type | Description |
|---|---|
| Object/Empty | Returns an object when a row is found; returns Empty if there is no result. |
Example
db = mysql('mysql://user:pass@127.0.0.1/test') row = db.query('select id, name from user where id=?').bind(1).one() // Output: Object echo(type(row))
Notes
- SQL must be set before execution.
- Batch configuration of binds, batch, and workers is not supported.
- The MySQL global connection pool grouped by DSN is reused by default; the pool status can be viewed through
BT.stats().mysql. - When there is no query result,
emptywill be returned, andnullwill not be used to indicate that it was not found. - Single call subject to
BT_MYSQL_QUERY_TIMEOUT_MSlimit.