Document toolboxDocument toolbox

Querying Data

query

Execute read-only SQL query on the database.

array query(string $sql, array $bind_parameters)

Parameters

$sql The query string. All data inside the query should be bound with named bind variables or properly escaped.
$bind_parameters An array of key-value pairs with elements that are bound parameters in the SQL statement being executed. Array key names match the named bind variables in the SQL statement.

Return Values

Returns FALSE on failure. For successful queries, it will return an array of data.

Example: Simple Services Query

$services = $this->query("SELECT * FROM SERVICES");

Example: Using Heredoc Notation

This example uses PHP heredoc Notation to query for Available Services

$services = $this->query(<<<SQL SELECT S.RECID, S.SERVICE_ID FROM SERVICES S LEFT JOIN LISTS ON S.SERVICE_STATUS_LISTS_RECID = LISTS.RECID WHERE LISTS.CODE = "AVAILABLE" SQL);

Example: Using Bind Variables

This example uses Bind Variables to query for Services with specified (Active and Available) Status Codes