/**
  * Stops the active profile
  *
  * @return PhalconProfiler
  */
 public function stopProfile()
 {
     $finalTime = microtime(true);
     $activeProfile = $this->_activeProfile;
     $activeProfile->setFinalTime($finalTime);
     $initialTime = $activeProfile->getInitialTime();
     $this->_totalSeconds = $this->_totalSeconds + ($finalTime - $initialTime);
     if ($this->_db) {
         $pdo = $this->_db->getInternalHandler();
         $sql = $activeProfile->getSQLStatement();
         $data = array('last_insert_id' => 0, 'affect_rows' => 0);
         $data['connection'] = $this->getConnectioinInfo();
         if (stripos($sql, 'INSERT') === 0) {
             $data['last_insert_id'] = $pdo->lastInsertId();
         }
         if (stripos($sql, 'INSERT') === 0 || stripos($sql, 'UPDATE') === 0 || stripos($sql, 'DELETE') === 0) {
             $data['affect_rows'] = $this->_db->affectedRows();
         }
         if (stripos($sql, 'SELECT') === 0 && $this->_explainQuery) {
             $stmt = $pdo->prepare('explain ' . $activeProfile->getSQLStatement());
             $stmt->execute($activeProfile->getSQLVariables());
             $data['explain'] = $stmt->fetchAll(\PDO::FETCH_CLASS);
         }
         $activeProfile->setExtra($data);
     }
     $this->_allProfiles[] = $activeProfile;
     if (method_exists($this, "afterEndProfile")) {
         $this->afterEndProfile($activeProfile);
     }
     $this->_stoped = true;
     return $this;
 }
Beispiel #2
0
 /**
  * Constructor for \Phalcon\Db\Adapter\Pdo
  *
  * @param array $descriptor
  * @throws Exception
  */
 public function __construct($descriptor)
 {
     if (is_array($descriptor) === false) {
         throw new Exception('The descriptor must be an array');
     }
     $this->connect($descriptor);
     parent::__construct($descriptor);
 }
Beispiel #3
0
 /**
  * Start the query benchmark
  *
  * @param Event $event
  * @param Adapter $database
  */
 public function beforeQuery(Event $event, Adapter $database)
 {
     $metadata = ['query' => $database->getSQLStatement()];
     $params = $database->getSQLVariables();
     if (isset($params)) {
         $metadata['params'] = $params;
     }
     $bindtypes = $database->getSQLBindTypes();
     if (isset($bindtypes)) {
         $metadata['bindTypes'] = $bindtypes;
     }
     $desc = $database->getDescriptor();
     if (isset($desc['dbname'])) {
         $metadata['database'] = $desc['dbname'];
     }
     $this->benchmark = $this->getProfiler()->start(get_class($event->getSource()) . '::query', $metadata, 'Database');
 }
Beispiel #4
0
 /**
  * Creates new Cassandra adapter
  * @param array $descriptor - connection description
  */
 public function __construct($descriptor)
 {
     $this->_transactionLevel = 0;
     $this->_type = 'cassandra';
     $this->_dialectType = 'cassandra';
     $this->_schemaCache = array();
     if (empty($descriptor['dialectClass'])) {
         $descriptor['dialectClass'] = 'PhalconCassandra\\Db\\Dialect\\Cassandra';
     }
     parent::__construct($descriptor);
 }
 /**
  * Start the query benchmark
  *
  * @param Event $event
  * @param Adapter $database
  */
 public function beforeQuery(Event $event, Adapter $database)
 {
     $metadata = ['query' => $database->getSQLStatement()];
     $this->benchmark = $this->getProfiler()->start(get_class($event->getSource()) . '::query', $metadata, 'Database');
 }