/** * Connects to the database. * */ protected function _connect() { parent::_connect(); if (!$this->_initialized) { $this->_initialized = true; if ($this->_config['timezone']) { // Requires PHP 5.2+ $dtz = new DateTimeZone($this->_config['timezone']); $offset = $dtz->getOffset(new DateTime('NOW')) / 60 / 60; if ($offset > 0) { $offset = "+" . $offset; } /* echo "location: ".$dtz->getLocation()."<br />"; echo "offset: ".$dtz->getOffset(new DateTime('NOW'))."<br />"; echo "offset 2: ". $offset."<br />"; echo "SET time_zone = '$offset:00'"."<br />"; */ $this->query("SET time_zone = '{$offset}:00';"); //sprintf("SET time_zone = '%d:00'", $offset)); /* $timezone = new DateTimeZone($this->_config['timezone']); $minutes = $timezone->getOffset(new DateTime('NOW')) / 60 / 60; //$offset = sprintf("SET time_zone = '%d:%2d'", $minutes / 60, $minutes % 60); $offset = sprintf("SET time_zone = '%d:00'", $offset); * */ } } }
/** * Modifies standard connection behavior to use UTF-8. * * @return void */ protected function _connect() { // if we already have a PDO object, no need to re-connect. if (is_null($this->_connection) === false) { return; } $config = Zend_Registry::get('Zend_Config'); if (isset($config, $config->db->debug) && $config->db->debug) { $logger = Zend_Registry::get('Zend_Log'); $logger->debug("Mysqlutf8: created new adapter"); $backtrace = debug_backtrace(false); foreach ($backtrace as $row) { $file = array_key_exists('file', $row) ? $row['file'] : '_no_file_)'; $line = array_key_exists('line', $row) ? $row['line'] : '0'; $function = array_key_exists('function', $row) ? $row['function'] : '_no_function_'; $optional = ''; if ($row['function'] == 'query' && !is_null($row['args'][0])) { $optional = "(" . $row['args'][0] . ")"; } $logger->debug("Mysqlutf8: {$file}:{$line} at {$function} {$optional}"); } } parent::_connect(); // set connection to utf8 $this->query('SET NAMES utf8'); // Enable "strict" mode on all transactional tables to avoid silent // truncation of inserted/updated data. See ticket [OPUSVIER-2111]. // $this->query("SET sql_mode = 'STRICT_TRANS_TABLES'"); }
/** * Connects to the database. This method is overridden because we need to set * some connection params that are not set by default, and that developers might * forget to set. Also addional checks are provided * * @return void * @throws Zend_Db_Adapter_Exception */ protected function _connect() { if ($this->_connection) { return; } if (!extension_loaded('pdo_mysql')) { require_once 'Zend/Db/Adapter/Exception.php'; throw new Zend_Db_Adapter_Exception('pdo_mysql extension is not installed'); } if (array_key_exists('host', $this->_config)) { if (strpos($this->_config['host'], '/') !== false) { $this->_config['unix_socket'] = $this->_config['host']; unset($this->_config['host']); } elseif (strpos($this->_config['host'], ':') !== false) { list($this->_config['host'], $this->_config['port']) = explode(':', $this->_config['host']); } } parent::_connect(); /** @link http://bugs.mysql.com/bug.php?id=18551 */ // dont know if we want this behaviour, check the link above $this->_connection->query("SET SQL_MODE=''"); $this->_connection->query("SET NAMES 'utf8'"); if (!$this->_connectionFlagsSet) { $this->_connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $this->_connectionFlagsSet = true; } }
protected function _connect() { // if we already have a PDO object, no need to re-connect. if ($this->_connection) { return; } parent::_connect(); // set connection to utf8 $this->query('SET NAMES utf8'); }
/** * Creates a PDO object and connects to the database. * * @return void * @throws Zend_Db_Adapter_Exception */ protected function _connect() { if ($this->_connection) { return; } if (!empty($this->_config['timeout'])) { $this->_config['driver_options'][PDO::ATTR_TIMEOUT] = $this->_config['timeout']; } parent::_connect(); }
/** * Creates a PDO object and connects to the database. * * @return void * @throws Zend_Db_Adapter_Exception */ protected function _connect() { if ($this->_connection) { return; } parent::_connect(); if (isset($this->_config['options']['init_commands']) && is_array($this->_config['options']['init_commands'])) { foreach ($this->_config['options']['init_commands'] as $sqlInitCommand) { $this->_connection->exec($sqlInitCommand); } } }
/** * Creates a PDO object and connects to the database. * * @return void * @throws Zend_Db_Adapter_Exception */ protected function _connect() { // if we already have a PDO object, no need to re-connect. if ($this->_connection) { return; } try { parent::_connect(); } catch (Exception $e) { $message = $e->getMessage(); $message = str_replace(array($this->_config['username'], $this->_config['password']), '******', $message); throw new Zend_Db_Adapter_Exception($message, $e->getCode(), $e->getPrevious()); } // finally, we delete the authorization data unset($this->_config['username'], $this->_config['password']); }
protected function _connect() { if ($this->_connection) { return; } if (!extension_loaded('pdo_mysql')) { throw new Zend_Db_Adapter_Exception('pdo_mysql extension is not installed'); } if (strpos($this->_config['host'], '/') !== false) { $this->_config['unix_socket'] = $this->_config['host']; $this->_config['host'] = null; } elseif (strpos($this->_config['host'], ':') !== false) { list($this->_config['host'], $this->_config['port']) = explode(':', $this->_config['host']); } parent::_connect(); /** @link http://bugs.mysql.com/bug.php?id=18551 */ $this->_connection->query("SET SQL_MODE=''"); if (!$this->_connectionFlagsSet) { $this->_connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); #$this->_connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); $this->_connectionFlagsSet = true; } }
/** * Creates a PDO object and connects to the database. * * @throws Zend_Db_Adapter_Exception */ protected function _connect() { if ($this->_connection) { return; } if (!extension_loaded('pdo_mysql')) { throw new Zend_Db_Adapter_Exception('pdo_mysql extension is not installed'); } $hostInfo = $this->_getHostInfo($this->_config['host']); switch ($hostInfo->getAddressType()) { case self::ADDRESS_TYPE_UNIX_SOCKET: $this->_config['unix_socket'] = $hostInfo->getUnixSocket(); unset($this->_config['host']); break; case self::ADDRESS_TYPE_IPV6_ADDRESS: // break intentionally omitted // break intentionally omitted case self::ADDRESS_TYPE_IPV4_ADDRESS: // break intentionally omitted // break intentionally omitted case self::ADDRESS_TYPE_HOSTNAME: $this->_config['host'] = $hostInfo->getHostName(); if ($hostInfo->getPort()) { $this->_config['port'] = $hostInfo->getPort(); } break; default: break; } $this->_debugTimer(); parent::_connect(); $this->_debugStat(self::DEBUG_CONNECT, ''); /** @link http://bugs.mysql.com/bug.php?id=18551 */ $this->_connection->query("SET SQL_MODE=''"); if (!$this->_connectionFlagsSet) { $this->_connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $this->_connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); $this->_connectionFlagsSet = true; } }
/** * Creates a PDO object and connects to the database. * * @return void * @throws \Zend_Db_Adapter_Exception */ protected function _connect() { if ($this->_connection) { return; } if (!extension_loaded('pdo_mysql')) { throw new \Zend_Db_Adapter_Exception('pdo_mysql extension is not installed'); } if (!isset($this->_config['host'])) { throw new \Zend_Db_Adapter_Exception('No host configured to connect'); } if (strpos($this->_config['host'], '/') !== false) { $this->_config['unix_socket'] = $this->_config['host']; unset($this->_config['host']); } elseif (strpos($this->_config['host'], ':') !== false) { list($this->_config['host'], $this->_config['port']) = explode(':', $this->_config['host']); } $this->logger->startTimer(); parent::_connect(); $this->logger->logStats(LoggerInterface::TYPE_CONNECT, ''); /** @link http://bugs.mysql.com/bug.php?id=18551 */ $this->_connection->query("SET SQL_MODE=''"); if (!$this->_connectionFlagsSet) { $this->_connection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true); $this->_connection->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); $this->_connectionFlagsSet = true; } }