Exemple #1
0
 /**
  * Connects to the database if needed.
  *
  * @return  void  Returns void if the database connected successfully.
  *
  * @since   __DEPLOY_VERSION__
  * @throws  \RuntimeException
  */
 public function connect()
 {
     if ($this->getConnection()) {
         return;
     }
     parent::connect();
     $this->setQuery('SET standard_conforming_strings = off')->execute();
 }
 /**
  * Connects to the database if needed.
  *
  * @return  void  Returns void if the database connected successfully.
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function connect()
 {
     parent::connect();
     $this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     $this->connection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
 }
Exemple #3
0
 /**
  * Connects to the database if needed.
  *
  * @return  void  Returns void if the database connected successfully.
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function connect()
 {
     if ($this->getConnection()) {
         return;
     }
     try {
         // Try to connect to MySQL
         parent::connect();
     } catch (ConnectionFailureException $e) {
         // If the connection failed, but not because of the wrong character set, then bubble up the exception.
         if (!$this->utf8mb4) {
             throw $e;
         }
         /*
          * Otherwise, try connecting again without using utf8mb4 and see if maybe that was the problem. If the connection succeeds, then we
          * will have learned that the client end of the connection does not support utf8mb4.
          */
         $this->utf8mb4 = false;
         $this->options['charset'] = 'utf8';
         parent::connect();
     }
     if ($this->utf8mb4) {
         // At this point we know the client supports utf8mb4.  Now we must check if the server supports utf8mb4 as well.
         $serverVersion = $this->connection->getAttribute(\PDO::ATTR_SERVER_VERSION);
         $this->utf8mb4 = version_compare($serverVersion, '5.5.3', '>=');
         if (!$this->utf8mb4) {
             // Reconnect with the utf8 character set.
             parent::disconnect();
             $this->options['charset'] = 'utf8';
             parent::connect();
         }
     }
     $this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     $this->connection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
 }
Exemple #4
0
 /**
  * Connects to the database if needed.
  *
  * @return  void  Returns void if the database connected successfully.
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function connect()
 {
     if ($this->getConnection()) {
         return;
     }
     parent::connect();
     if (isset($this->options['schema'])) {
         $this->setQuery('ALTER SESSION SET CURRENT_SCHEMA = ' . $this->quoteName($this->options['schema']))->execute();
     }
     $this->setDateFormat($this->dateformat);
 }