Chris@0: dbh = $dbh; Chris@0: $this->setFetchMode(\PDO::FETCH_OBJ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function execute($args = [], $options = []) { Chris@0: if (isset($options['fetch'])) { Chris@0: if (is_string($options['fetch'])) { Chris@0: // \PDO::FETCH_PROPS_LATE tells __construct() to run before properties Chris@0: // are added to the object. Chris@0: $this->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, $options['fetch']); Chris@0: } Chris@0: else { Chris@0: $this->setFetchMode($options['fetch']); Chris@0: } Chris@0: } Chris@0: Chris@0: $logger = $this->dbh->getLogger(); Chris@0: if (!empty($logger)) { Chris@0: $query_start = microtime(TRUE); Chris@0: } Chris@0: Chris@0: $return = parent::execute($args); Chris@0: Chris@0: if (!empty($logger)) { Chris@0: $query_end = microtime(TRUE); Chris@0: $logger->log($this, $args, $query_end - $query_start); Chris@0: } Chris@0: Chris@0: return $return; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getQueryString() { Chris@0: return $this->queryString; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function fetchCol($index = 0) { Chris@0: return $this->fetchAll(\PDO::FETCH_COLUMN, $index); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function fetchAllAssoc($key, $fetch = NULL) { Chris@0: $return = []; Chris@0: if (isset($fetch)) { Chris@0: if (is_string($fetch)) { Chris@0: $this->setFetchMode(\PDO::FETCH_CLASS, $fetch); Chris@0: } Chris@0: else { Chris@0: $this->setFetchMode($fetch); Chris@0: } Chris@0: } Chris@0: Chris@0: foreach ($this as $record) { Chris@0: $record_key = is_object($record) ? $record->$key : $record[$key]; Chris@0: $return[$record_key] = $record; Chris@0: } Chris@0: Chris@0: return $return; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function fetchAllKeyed($key_index = 0, $value_index = 1) { Chris@0: $return = []; Chris@0: $this->setFetchMode(\PDO::FETCH_NUM); Chris@0: foreach ($this as $record) { Chris@0: $return[$record[$key_index]] = $record[$value_index]; Chris@0: } Chris@0: return $return; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function fetchField($index = 0) { Chris@0: // Call \PDOStatement::fetchColumn to fetch the field. Chris@0: return $this->fetchColumn($index); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function fetchAssoc() { Chris@0: // Call \PDOStatement::fetch to fetch the row. Chris@0: return $this->fetch(\PDO::FETCH_ASSOC); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function rowCount() { Chris@0: // SELECT query should not use the method. Chris@0: if ($this->allowRowCount) { Chris@0: return parent::rowCount(); Chris@0: } Chris@0: else { Chris@0: throw new RowCountException(); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setFetchMode($mode, $a1 = NULL, $a2 = []) { Chris@0: // Call \PDOStatement::setFetchMode to set fetch mode. Chris@0: // \PDOStatement is picky about the number of arguments in some cases so we Chris@0: // need to be pass the exact number of arguments we where given. Chris@0: switch (func_num_args()) { Chris@0: case 1: Chris@0: return parent::setFetchMode($mode); Chris@0: case 2: Chris@0: return parent::setFetchMode($mode, $a1); Chris@0: case 3: Chris@0: default: Chris@0: return parent::setFetchMode($mode, $a1, $a2); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function fetchAll($mode = NULL, $column_index = NULL, $constructor_arguments = NULL) { Chris@0: // Call \PDOStatement::fetchAll to fetch all rows. Chris@0: // \PDOStatement is picky about the number of arguments in some cases so we Chris@0: // need to be pass the exact number of arguments we where given. Chris@0: switch (func_num_args()) { Chris@0: case 0: Chris@0: return parent::fetchAll(); Chris@0: case 1: Chris@0: return parent::fetchAll($mode); Chris@0: case 2: Chris@0: return parent::fetchAll($mode, $column_index); Chris@0: case 3: Chris@0: default: Chris@0: return parent::fetchAll($mode, $column_index, $constructor_arguments); Chris@0: } Chris@0: } Chris@0: Chris@0: }