Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

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

$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 IN (:statusCodes)
SQL, [':statusCodes' => ['ACTIVE', 'AVAILABLE']]);
  • No labels