33 lines
1012 B
Plaintext
33 lines
1012 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.
|
|
|
|
Related:
|
|
|
|
- PHP: modern database access through `mysqli_*` or PDO methods rather than the old `mysql_*` family
|
|
- JavaScript / Node.js: clients such as `mysql2`, query builders, or ORM adapters
|