public function getAdapterConnection($datasource)
 {
     if (!isset($this->adapterConnections[$datasource])) {
         $buildConnection = $this->getConnection($datasource);
         $conn = ConnectionFactory::create($buildConnection, AdapterFactory::create($buildConnection['adapter']));
         $this->adapterConnections[$datasource] = $conn;
     }
     return $this->adapterConnections[$datasource];
 }
Пример #2
0
 public function testQuoteConnected()
 {
     $p = $this->getPlatform();
     $p->setConnection(ConnectionFactory::create(['dsn' => 'sqlite::memory:'], AdapterFactory::create('sqlite')));
     $unquoted = "Naughty ' string";
     $quoted = $p->quote($unquoted);
     $expected = "'Naughty '' string'";
     $this->assertEquals($expected, $quoted);
 }
Пример #3
0
 /**
  * Return a connection object of a given database name
  *
  * @param  string              $database
  * @return ConnectionInterface
  */
 public function getConnection($database = null)
 {
     $buildConnection = $this->getBuildConnection($database);
     //Still useful ?
     //$dsn = str_replace("@DB@", $database, $buildConnection['dsn']);
     $dsn = $buildConnection['dsn'];
     // Set user + password to null if they are empty strings or missing
     $username = isset($buildConnection['user']) && $buildConnection['user'] ? $buildConnection['user'] : null;
     $password = isset($buildConnection['password']) && $buildConnection['password'] ? $buildConnection['password'] : null;
     $con = ConnectionFactory::create(array('dsn' => $dsn, 'user' => $username, 'password' => $password), AdapterFactory::create($buildConnection['adapter']));
     return $con;
 }
 /**
  * @return ConnectionInterface
  */
 protected function getConnection()
 {
     $buildConnection = $this->connection;
     // Set user + password to null if they are empty strings or missing
     $username = isset($buildConnection['user']) && $buildConnection['user'] ? $buildConnection['user'] : null;
     $password = isset($buildConnection['password']) ? $buildConnection['password'] : null;
     $con = ConnectionFactory::create(array('dsn' => $buildConnection['dsn'], 'user' => $username, 'password' => $password), AdapterFactory::create($buildConnection['adapter']));
     return $con;
 }
Пример #5
0
 private function testConnection(ConsoleHelperInterface $consoleHelper, array $options)
 {
     $adapter = AdapterFactory::create($options['rdbms']);
     try {
         ConnectionFactory::create($options, $adapter);
         $consoleHelper->writeBlock('Connected to sql server successful!');
         return true;
     } catch (ConnectionException $e) {
         // get the "real" wrapped exception message
         do {
             $message = $e->getMessage();
         } while (null !== ($e = $e->getPrevious()));
         $consoleHelper->writeBlock('Unable to connect to the specific sql server: ' . $message, 'error');
         $consoleHelper->writeSection('Make sure the specified credentials are correct and try it again.');
         $consoleHelper->writeln('');
         if (OutputInterface::VERBOSITY_DEBUG === $consoleHelper->getOutput()->getVerbosity()) {
             $consoleHelper->writeln($e);
         }
         return false;
     }
 }
Пример #6
0
 /**
  * Get the adapter for a given datasource.
  *
  * If the adapter does not yet exist, build it using the related adapterClass.
  *
  * @param string $name The datasource name
  *
  * @return Propel\Runtime\Adapter\AdapterInterface
  */
 public function getAdapter($name = null)
 {
     if ($name === null) {
         $name = $this->getDefaultDatasource();
     }
     if (!isset($this->adapters[$name])) {
         if (!isset($this->adapterClasses[$name])) {
             throw new PropelException(sprintf('No adapter class defined for datasource "%s"', $name));
         }
         $this->adapters[$name] = AdapterFactory::create($this->adapterClasses[$name]);
     }
     return $this->adapters[$name];
 }
Пример #7
0
 /**
  * Returns a ConnectionInterface instance for a given datasource.
  *
  * @param  string              $datasource
  * @return ConnectionInterface
  */
 protected function getConnectionInstance($datasource)
 {
     $buildConnection = $this->getConnection($datasource);
     $dsn = str_replace("@DB@", $datasource, $buildConnection['dsn']);
     // Set user + password to null if they are empty strings or missing
     $username = isset($buildConnection['user']) && $buildConnection['user'] ? $buildConnection['user'] : null;
     $password = isset($buildConnection['password']) && $buildConnection['password'] ? $buildConnection['password'] : null;
     $con = ConnectionFactory::create(array('dsn' => $dsn, 'user' => $username, 'password' => $password), AdapterFactory::create($buildConnection['adapter']));
     return $con;
 }