/** * Create a new connection */ private function connect() { $genericAdapterOptions = self::$genericAdapterOptions; $driverOptions = self::$driverOptions; $adapterParamaters = array('host' => $this->config->host, 'username' => $this->config->username, 'password' => $this->config->password, 'dbname' => $this->config->dbname, 'options' => &$genericAdapterOptions, 'driver_options' => &$driverOptions); $this->dbType = strtolower($this->config->get('db', 'mysql')); switch ($this->dbType) { case 'mysql': $adapter = 'Pdo_Mysql'; /* * Set MySQL server SQL modes to behave as closely as possible to Oracle and PostgreSQL. Note that the * ONLY_FULL_GROUP_BY mode is left on purpose because MySQL requires you to specify all non-aggregate * columns in the group by list even if the query is grouped by the master table's primary key which is * valid ANSI SQL though. Further in that case the query plan would suffer if you add more columns to * the group by list. */ $driverOptions[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET SESSION SQL_MODE=\'STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,' . 'NO_AUTO_CREATE_USER,ANSI_QUOTES,PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION\';'; $adapterParamaters['port'] = $this->config->get('port', 3306); break; case 'pgsql': $adapter = 'Pdo_Pgsql'; $adapterParamaters['port'] = $this->config->get('port', 5432); if ($adapterParamaters['host'] === '') { unset($adapterParamaters['host']); } break; /*case 'oracle': if ($this->dbtype === 'oracle') { $attributes['persistent'] = true; } $this->db = ZfDb::factory($adapter, $attributes); if ($adapter === 'Oracle') { $this->db->setLobAsString(false); } break;*/ /*case 'oracle': if ($this->dbtype === 'oracle') { $attributes['persistent'] = true; } $this->db = ZfDb::factory($adapter, $attributes); if ($adapter === 'Oracle') { $this->db->setLobAsString(false); } break;*/ default: throw new ConfigurationError('Backend "%s" is not supported', $this->dbType); } $this->dbAdapter = Zend_Db::factory($adapter, $adapterParamaters); $this->dbAdapter->setFetchMode(Zend_Db::FETCH_OBJ); // TODO(el/tg): The profiler is disabled per default, why do we disable the profiler explicitly? $this->dbAdapter->getProfiler()->setEnabled(false); }
/** * _authenticateQuerySelect() - This method accepts a Zend_Db_Select object and * performs a query against the database with that object. * * @param Zend_Db_Select $dbSelect * @throws \Zend\Authentication\Adapter\Exception - when an invalid select * object is encountered * @return array */ protected function _authenticateQuerySelect(\Zend_Db_Select $dbSelect) { try { if ($this->_zendDb->getFetchMode() != \Zend_DB::FETCH_ASSOC) { $origDbFetchMode = $this->_zendDb->getFetchMode(); $this->_zendDb->setFetchMode(\Zend_DB::FETCH_ASSOC); } $resultIdentities = $this->_zendDb->fetchAll($dbSelect->__toString()); if (isset($origDbFetchMode)) { $this->_zendDb->setFetchMode($origDbFetchMode); unset($origDbFetchMode); } } catch (\Exception $e) { throw new Exception('The supplied parameters to Zend\\Authentication\\Adapter\\DbTable failed to ' . 'produce a valid sql statement, please check table and column names ' . 'for validity.', 0, $e); } return $resultIdentities; }
/** * _authenticateQuerySelect() - This method accepts a Zend_Db_Select object and * performs a query against the database with that object. * * @param Zend_Db_Select $dbSelect * @throws Zend_Auth_Adapter_Exception - when an invalid select * object is encountered * @return array */ protected function _authenticateQuerySelect(Zend_Db_Select $dbSelect) { try { if ($this->_zendDb->getFetchMode() != Zend_DB::FETCH_ASSOC) { $origDbFetchMode = $this->_zendDb->getFetchMode(); $this->_zendDb->setFetchMode(Zend_DB::FETCH_ASSOC); } $resultIdentities = $this->_zendDb->fetchAll($dbSelect->__toString()); if (isset($origDbFetchMode)) { $this->_zendDb->setFetchMode($origDbFetchMode); unset($origDbFetchMode); } } catch (Exception $e) { /** * @see Zend_Auth_Adapter_Exception */ require_once 'Zend/Auth/Adapter/Exception.php'; throw new Zend_Auth_Adapter_Exception('The supplied parameters to Zend_Auth_Adapter_DbTable failed to ' . 'produce a valid sql statement, please check table and column names ' . 'for validity.', 0, $e); } return $resultIdentities; }
/** * _authenticateQuerySelect() - This method accepts a Zend_Db_Select object and * performs a query against the database with that object. * * @param Zend_Db_Select $dbSelect * @throws Zend_Auth_Adapter_Exception - when an invalid select * object is encountered * @return array */ protected function _authenticateQuerySelect(Zend_Db_Select $dbSelect) { try { if ($this->_zendDb->getFetchMode() != Zend_DB::FETCH_ASSOC) { $origDbFetchMode = $this->_zendDb->getFetchMode(); $this->_zendDb->setFetchMode(Zend_DB::FETCH_ASSOC); } $resultIdentities = $this->_zendDb->fetchAll($dbSelect); if (isset($origDbFetchMode)) { $this->_zendDb->setFetchMode($origDbFetchMode); unset($origDbFetchMode); } } catch (Exception $e) { /** * @see Zend_Auth_Adapter_Exception */ require_once 'Zend/Auth/Adapter/Exception.php'; throw new Zend_Auth_Adapter_Exception('O sistema falhou ao tentar executar o script de autenticação. ' . 'Por favor, entre em contato com o suporte ' . 'e informe o ocorrido..', 0, $e); } return $resultIdentities; }
/** * Support method for fetching rows. * * @param string $type Whether to fetch 'all' or 'row'. * @param string|array $where OPTIONAL An SQL WHERE clause. * @param string|array $order OPTIONAL An SQL ORDER clause. * @param int $count OPTIONAL An SQL LIMIT count. * @param int $offset OPTIONAL An SQL LIMIT offset. * @return mixed The row results per the Zend_Db_Adapter fetch mode. */ protected function _fetch($type, $where = null, $order = null, $count = null, $offset = null) { // selection tool $select = $this->_db->select(); // the FROM clause $select->from($this->_name, $this->_cols); // the WHERE clause $where = (array) $where; foreach ($where as $key => $val) { // is $key an int? if (is_int($key)) { // $val is the full condition $select->where($val); } else { // $key is the condition with placeholder, // and $val is quoted into the condition $select->where($key, $val); } } // the ORDER clause if (!is_array($order)) { $order = array($order); } foreach ($order as $val) { $select->order($val); } // the LIMIT clause $select->limit($count, $offset); // return the results $method = "fetch{$type}"; $mode = $this->_db->getFetchMode(); $this->_db->setFetchMode(Zend_Db::FETCH_ASSOC); $data = $this->_db->{$method}($select); $this->_db->setFetchMode($mode); return $data; }
/** * Set the fetch mode. * * @param integer $mode fetch mode * @return void * @throws Zend_Db_Adapter_Exception */ public function setFetchMode($mode) { return $this->_adapter->setFetchMode($mode); }
/** * Create a new connection */ private function connect() { $genericAdapterOptions = self::$genericAdapterOptions; $driverOptions = self::$driverOptions; $adapterParamaters = array('host' => $this->config->host, 'username' => $this->config->username, 'password' => $this->config->password, 'dbname' => $this->config->dbname, 'charset' => $this->config->charset ?: null, 'persistent' => (bool) $this->config->get('persistent', false), 'options' => &$genericAdapterOptions, 'driver_options' => &$driverOptions); $this->dbType = strtolower($this->config->get('db', 'mysql')); switch ($this->dbType) { case 'mssql': $adapter = 'Pdo_Mssql'; $adapterParamaters['pdoType'] = $this->config->get('pdoType', 'dblib'); break; case 'mysql': $adapter = 'Pdo_Mysql'; if ($this->config->use_ssl) { # The presence of these keys as empty strings or null cause non-ssl connections to fail if ($this->config->ssl_key) { $adapterParamaters['driver_options'][PDO::MYSQL_ATTR_SSL_KEY] = $this->config->ssl_key; } if ($this->config->ssl_cert) { $adapterParamaters['driver_options'][PDO::MYSQL_ATTR_SSL_CERT] = $this->config->ssl_cert; } if ($this->config->ssl_ca) { $adapterParamaters['driver_options'][PDO::MYSQL_ATTR_SSL_CA] = $this->config->ssl_ca; } if ($this->config->ssl_capath) { $adapterParamaters['driver_options'][PDO::MYSQL_ATTR_SSL_CAPATH] = $this->config->ssl_capath; } if ($this->config->ssl_cipher) { $adapterParamaters['driver_options'][PDO::MYSQL_ATTR_SSL_CIPHER] = $this->config->ssl_cipher; } } /* * Set MySQL server SQL modes to behave as closely as possible to Oracle and PostgreSQL. Note that the * ONLY_FULL_GROUP_BY mode is left on purpose because MySQL requires you to specify all non-aggregate * columns in the group by list even if the query is grouped by the master table's primary key which is * valid ANSI SQL though. Further in that case the query plan would suffer if you add more columns to * the group by list. */ $driverOptions[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET SESSION SQL_MODE=\'STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,' . 'NO_AUTO_CREATE_USER,ANSI_QUOTES,PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION\''; if (isset($adapterParamaters['charset'])) { $driverOptions[PDO::MYSQL_ATTR_INIT_COMMAND] .= ', NAMES ' . $adapterParamaters['charset']; unset($adapterParamaters['charset']); } $driverOptions[PDO::MYSQL_ATTR_INIT_COMMAND] .= ';'; $adapterParamaters['port'] = $this->config->get('port', 3306); break; case 'oci': $adapter = 'Oracle'; unset($adapterParamaters['options']); unset($adapterParamaters['driver_options']); $adapterParamaters['driver_options'] = array('lob_as_string' => true); break; case 'oracle': $adapter = 'Pdo_Oci'; break; case 'pgsql': $adapter = 'Pdo_Pgsql'; $adapterParamaters['port'] = $this->config->get('port', 5432); break; default: throw new ConfigurationError('Backend "%s" is not supported', $this->dbType); } $this->dbAdapter = Zend_Db::factory($adapter, $adapterParamaters); $this->dbAdapter->setFetchMode(Zend_Db::FETCH_OBJ); // TODO(el/tg): The profiler is disabled per default, why do we disable the profiler explicitly? $this->dbAdapter->getProfiler()->setEnabled(false); }