webCOMAND

query::get_rows()

Similar to get(), except a rowset of results is returned instead of a collection, which is more efficient because full objects are not created.

Prototype

get_rows(array $options = []): collection

Parameters

  • options - An associative array with zero or more of the following key/value pairs.
    • checksum - If TRUE, a checksum unique to the resulting collection will be made available for retrieval with collection::get_result_checksum().  Otherwise do not produce a checksum (default).
    • checksum_only - If TRUE, only produce the checksum, and do not return the results.  This is the most efficient way to produce a checksum if you do not need the results.
    • bind - An array of values to bind to ? placeholders, or an  associative array of keys and values to bind to :key placeholders.  As an alternative, call bind().

Return

A collection of objects resulting from the query, or FALSE if there was an error.

Example (Chained)

// create, assemble and execute the query as one chained statement
$contacts = $repo->query()
	->select('Name', 'Phone');
	->from('Contact');
	->where('Name', 'John');
	->get_rows();

// iterate through the collection results
foreach($contacts as $contact) {
	print($contact['Name'] . ": " . $contact['Phone'] . "\n");
}

Example (Long-hand)

// create and assemble the query, one clause at a time
$query = $repo->query();
$query->select('Name', 'Phone');
$query->from('Contact');
$query->where('Name', 'John');

// execute the query assembled above
$contacts = $query->get_rows();

// iterate through the collection results
foreach($contacts as $contact) {
	print($contact->Name . ": " . $contact->Phone . "\n");
}