This function runs an SQL select statement a on the database represented by alias b. Placeholders in the form ¶meterNumber in the statement are replaced by the values of parameters c to j. Characters required for valid syntax (for example, quotes around strings) must already be part of the statement. The function automatically limits the number of selected result rows to 1.
If the database returns a result row, the function returns the value of the first column. Otherwise, it returns k.
If the result set contains columns of type BLOB, parameter l controls the encoding. Set l to true to write the binary data Base64-encoded to the result lists. Otherwise, the data remains unchanged. If there are no such columns in the result set, the parameter value has no effect.
IMPORTANT:
In addition to the
¶meterNumbernotation, you can also use the notation for prepared statements in the form@parameterNumber:parameterType@. Prefer prepared statements, because they prevent SQL injection attacks.
Parameters
Parameter | Description |
|---|---|
a | SQL statement to run. |
b | The database alias. |
c | (optional) Parameter |
d | (optional) Parameter |
e | (optional) Parameter |
f | (optional) Parameter |
g | (optional) Parameter |
h | (optional) Parameter |
i | (optional) Parameter |
j | (optional) Parameter |
k | (optional) Return value if the database does not return a result. |
l | (optional) |
m | (optional) |
n | (optional) If |
Examples
Assume a table zipcodes that contains the ZIP codes of Germany (an imaginary 20000 entries).
Parameter a | b | c | d-j | k | l | m | n | Result |
|---|---|---|---|---|---|---|---|---|
| testdb | unknown | 01067 | |||||
| testdb | 80336 | unknown | Munich | ||||
| testdb | 00000 | unknown | unknown | ||||
| testdb | 80336 | unknown | Munich | ||||
| testdb | 00000 | unknown | unknown | ||||
| testdb | root | secret | unknown | 4711 | |||
| testdb | root |
| unknown | 4711 | |||
| testdb | root |
| unknown | unknown | |||
| testdb | root | secret | unknown | Error, because text literals must be enclosed in quotes. |