W3cubDocs

/Phalcon 2

Class Phalcon\Mvc\Model\Query

implements Phalcon\Mvc\Model\QueryInterface, Phalcon\DI\InjectionAwareInterface

This class takes a PHQL intermediate representation and executes it.

$phql = "SELECT c.price*0.16 AS taxes, c.* FROM Cars AS c JOIN Brands AS b
          WHERE b.name = :name: ORDER BY c.name";

 $result = $manager->executeQuery($phql, array(
   'name' => 'Lamborghini'
 ));

 foreach ($result as $row) {
   echo "Name: ", $row->cars->name, "\n";
   echo "Price: ", $row->cars->price, "\n";
   echo "Taxes: ", $row->taxes, "\n";
 }

Constants

integer TYPE_SELECT

integer TYPE_INSERT

integer TYPE_UPDATE

integer TYPE_DELETE

Methods

public __construct (string $phql)

Phalcon\Mvc\Model\Query constructor

public setDI (Phalcon\DiInterface $dependencyInjector)

Sets the dependency injection container

public Phalcon\DiInterface getDI ()

Returns the dependency injection container

public Phalcon\Mvc\Model\Query setUniqueRow (boolean $uniqueRow)

Tells to the query if only the first row in the resultset must be returned

public boolean getUniqueRow ()

Check if the query is programmed to get only the first row in the resultset

protected string _getQualified ()

Replaces the model’s name to its source name in a qualifed-name expression

protected string _getCallArgument ()

Resolves a expression in a single call argument

protected string _getFunctionCall ()

Resolves a expression in a single call argument

protected string _getExpression ()

Resolves an expression from its intermediate code into a string

protected array _getSelectColumn ()

Resolves a column from its intermediate representation into an array used to determine if the resulset produced is simple or complex

protected string _getTable ()

Resolves a table in a SELECT statement checking if the model exists

protected array _getJoin ()

Resolves a JOIN clause checking if the associated models exist

protected string _getJoinType ()

Resolves a JOIN type

protected array _getSingleJoin ()

Resolves joins involving has-one/belongs-to/has-many relations

protected array _getMultiJoin ()

Resolves joins involving many-to-many relations

protected array _getJoins ()

Processes the JOINs in the query returning an internal representation for the database dialect

protected string _getOrderClause ()

Returns a processed order clause for a SELECT statement

protected string _getGroupClause ()

Returns a processed group clause for a SELECT statement

protected _getLimitClause ()

...

protected array _prepareSelect ()

Analyzes a SELECT intermediate code and produces an array to be executed later

protected array _prepareInsert ()

Analyzes an INSERT intermediate code and produces an array to be executed later

protected array _prepareUpdate ()

Analyzes an UPDATE intermediate code and produces an array to be executed later

protected array _prepareDelete ()

Analyzes a DELETE intermediate code and produces an array to be executed later

public array parse ()

Parses the intermediate code produced by Phalcon\Mvc\Model\Query\Lang generating another intermediate representation that could be executed by Phalcon\Mvc\Model\Query

public Phalcon\Mvc\Model\Query cache (array $cacheOptions)

Sets the cache parameters of the query

public getCacheOptions ()

Returns the current cache options

public Phalcon\Cache\BackendInterface getCache ()

Returns the current cache backend instance

protected Phalcon\Mvc\Model\ResultsetInterface _executeSelect ()

Executes the SELECT intermediate representation producing a Phalcon\Mvc\Model\Resultset

protected Phalcon\Mvc\Model\Query\StatusInterface _executeInsert ()

Executes the INSERT intermediate representation producing a Phalcon\Mvc\Model\Query\Status

protected Phalcon\Mvc\Model\ResultsetInterface _getRelatedRecords ()

Query the records on which the UPDATE/DELETE operation well be done

protected Phalcon\Mvc\Model\Query\StatusInterface _executeUpdate ()

Executes the UPDATE intermediate representation producing a Phalcon\Mvc\Model\Query\Status

protected Phalcon\Mvc\Model\Query\StatusInterface _executeDelete ()

Executes the DELETE intermediate representation producing a Phalcon\Mvc\Model\Query\Status

public mixed execute ([array $bindParams], [array $bindTypes])

Executes a parsed PHQL statement

public ṔhalconMvcModelInterface getSingleResult ([array $bindParams], [array $bindTypes])

Executes the query returning the first result

public Phalcon\Mvc\Model\Query setType (int $type)

Sets the type of PHQL statement to be executed

public int getType ()

Gets the type of PHQL statement executed

public Phalcon\Mvc\Model\Query setBindParams (array $bindParams)

Set default bind parameters

public array getBindParams ()

Returns default bind params

public Phalcon\Mvc\Model\Query setBindTypes (array $bindTypes)

Set default bind parameters

public array getBindTypes ()

Returns default bind types

public Phalcon\Mvc\Model\Query setIntermediate (array $intermediate)

Allows to set the IR to be executed

public array getIntermediate ()

Returns the intermediate representation of the PHQL statement

© 2011–2016 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/2.0.0/api/Phalcon_Mvc_Model_Query.html