示例#1
0
 /**
  * The queries executed are stored in the cache
  *
  * @param  string                          $sqlStatement
  * @param  array                           $bindParams
  * @param  array                           $bindTypes
  * @return \Phalcon\Db\Result\Serializable
  */
 public function query($sqlStatement, $bindParams = null, $bindTypes = null)
 {
     /**
      * The key is the full sql statement + its parameters
      */
     if (is_array($bindParams)) {
         $key = \Phalcon\Kernel::preComputeHashKey($sqlStatement . '//' . join('|', $bindParams));
     } else {
         $key = \Phalcon\Kernel::preComputeHashKey($sqlStatement);
     }
     /**
      * Check if the result is already cached
      */
     if ($this->_cache->exists($key)) {
         $value = $this->_cache->get($key);
         if (!is_null($value)) {
             return $value;
         }
     }
     $this->internalConnect();
     /**
      * Executes the queries
      */
     $data = parent::query($sqlStatement, $bindParams, $bindTypes);
     if (is_object($data)) {
         $result = new Serializable($data);
         $this->_cache->save($key, $result);
         return $result;
     }
     $this->_cache->save($key, $data);
     return false;
 }
示例#2
0
 /**
  * Calling the parent execute method in PDO class
  *
  * @param String $sqlStatement
  * @param array  $bindParams
  * @param array  $bindTypes
  *
  * @return bool|\Phalcon\Db\ResultInterface
  */
 protected function callParentQuery($sqlStatement, $bindParams, $bindTypes)
 {
     return parent::query($sqlStatement, $bindParams, $bindTypes);
 }
示例#3
0
<?php

use Phalcon\Events\Manager as EventsManager, Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
$eventsManager = new EventsManager();
//Create a database listener
$dbListener = new MyDbListener();
//Listen all the database events
$eventsManager->attach('db', $dbListener);
$connection = new DbAdapter(array("host" => "localhost", "username" => "root", "password" => "secret", "dbname" => "invo"));
//Assign the eventsManager to the db adapter instance
$connection->setEventsManager($eventsManager);
//Send a SQL command to the database server
$connection->query("SELECT * FROM products p WHERE p.status = 1");