webCOMAND

collection::get_rows()

Query a collection and return a row set of matching objects field values.

Prototype

row_set get_rows(mixed $query, array $options = [])

Parameters

  • query - cPath string, cQL string, Query Object, cQL Array
  • options
    • bind - Array of variables to bind to the query.  If the binding is a question mark (ie. ?), the array index is an index to the question mark (first question mark is represented by index zero, etc.).  If the binding is a named binding (ie. :Name), the array index is the binding name.

Return

A row set of associative arrays that match the query.

Example

$contacts = $repo->get_rows("SELECT * FROM Contact WHERE Name='John'");
foreach($contacts as $contact) {
	echo($contact['Name'] . " - " . $contact['Phone'] . "\n");
}

Binding Example

$name = 'John';
$contacts = $repo->get_rows("SELECT Name, Phone FROM Contact WHERE Name=?",
    ['bind'=>array[$name]]);
foreach($contacts as $contact) {
	echo($contact['Name'] . " - " . $contact['Phone'] . "\n");
}

Binding Example

$name = 'John';
$contacts = $repo->get_rows("SELECT Name, Phone FROM Contact WHERE Name=:Name",
   ['bind'=>array('Name'=>$name]]);
foreach($contacts as $contact) {
	echo($contact['Name'] . " - " . $contact['Phone'] . "\n");
}