Exemplo n.º 1
0
 /**
  * @param array $params
  * @return void
  */
 public function execute($params = null)
 {
     if ($params !== null) {
         $this->params = $params;
     }
     EventEmitter::emit('hyperframework.db.prepared_statement_executing', [$this, $this->params]);
     $e = null;
     try {
         $this->pdoStatement->execute($params);
     } catch (Exception $e) {
         throw $e;
     } catch (Throwable $e) {
         throw $e;
     } finally {
         EventEmitter::emit('hyperframework.db.prepared_statement_executed', [$e === null ? 'success' : 'failure']);
     }
 }
 /**
  * @param string $sql
  * @param bool $isQuery
  * @param string $fetchOptions
  * @return mixed
  */
 private function sendSql($sql, $isQuery = false, $fetchOptions = null)
 {
     EventEmitter::emit('hyperframework.db.sql_statement_executing', [$this, $sql]);
     $result = null;
     $e = null;
     try {
         if ($isQuery) {
             if ($fetchOptions === null) {
                 $result = parent::query($sql);
             } else {
                 switch (count($fetchOptions)) {
                     case 0:
                         break;
                     case 1:
                         $result = parent::query($sql, $fetchOptions[0]);
                         break;
                     case 2:
                         $result = parent::query($sql, $fetchOptions[0], $fetchOptions[1]);
                         break;
                     default:
                         $result = parent::query($sql, $fetchOptions[0], $fetchOptions[1], $fetchOptions[2]);
                 }
             }
         } else {
             $result = parent::exec($sql);
         }
     } catch (Exception $e) {
         throw $e;
     } catch (Throwable $e) {
         throw $e;
     } finally {
         EventEmitter::emit('hyperframework.db.sql_statement_executed', [$e === null ? 'success' : 'failure']);
     }
     if ($isQuery) {
         return new DbStatement($result, $this);
     }
     return $result;
 }
 public function run()
 {
     EventEmitter::bindAll([['name' => 'hyperframework.db.transaction_operation_executing', 'callback' => [$this, 'onTransactionOperationExecuting']], ['name' => 'hyperframework.db.transaction_operation_executed', 'callback' => [$this, 'onTransactionOperationExecuted']], ['name' => 'hyperframework.db.sql_statement_executing', 'callback' => [$this, 'onSqlStatementExecuting']], ['name' => 'hyperframework.db.sql_statement_executed', 'callback' => [$this, 'onSqlStatementExecuted']], ['name' => 'hyperframework.db.prepared_statement_executing', 'callback' => [$this, 'onPreparedStatementExecuting']], ['name' => 'hyperframework.db.prepared_statement_executed', 'callback' => [$this, 'onPreparedStatementExecuted']]]);
 }