webCOMAND

repo::get()

Query a repository and return a collection of matching objects.

New to COMAND queries?  Check out the COMAND API Queries Tutorial.

Prototype

collection get(mixed $query, array $options = [])

Parameters

  • query - cPath string, cQL string, Query Object or 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.  As an alternative, use query::bind().

Return

A collection of objects that match the query.

For information about query performance and object caching, see Repository Object Cache.

Examples

cQL Example

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

? Binding Example

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

:Name Binding Example

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