31 lines
938 B
Plaintext
31 lines
938 B
Plaintext
:sig
|
|
DValue mysql_query(MySQL* m, String q, StringMap params)
|
|
|
|
:params
|
|
m : pointer to an active MySQL connection struct
|
|
q : a string containing a MySQL query
|
|
params : optional, a list of query parameter keys and values
|
|
return value : a list of rows returned from executing the query
|
|
|
|
:see
|
|
>mysql
|
|
|
|
:content
|
|
Executes a MySQL query and returns the resulting data, if any.
|
|
|
|
`params` provides the query parameter values used by the statement. Use named `:name` placeholders only; positional `?` placeholders are rejected.
|
|
|
|
```cpp
|
|
StringMap params;
|
|
params["email"] = "ada@example.test";
|
|
DValue rows = mysql_query(m,
|
|
"select id, email from users where email = :email",
|
|
params
|
|
);
|
|
```
|
|
|
|
The result is returned as a `DValue`, which makes it easy to iterate through rows and read fields with the usual `DValue` accessors.
|
|
|
|
:example
|
|
print("mysql_query is resource-bound; configure the service or connection, then call it in request code.\n");
|