コード例 #1
0
 /**
  * @param  \Propel\Runtime\Adapter\AdapterInterface $adapter
  *
  * @return \Propel\Runtime\Connection\ConnectionInterface
  */
 public function getWriteConnection(AdapterInterface $adapter = null)
 {
     if (null === $this->connection) {
         $this->connection = ConnectionFactory::create($this->configuration, $adapter);
     }
     return $this->connection;
 }
コード例 #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
 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];
 }
コード例 #4
0
ファイル: GeneratorConfig.php プロジェクト: hhamon/Propel2
 /**
  * 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;
 }
コード例 #5
0
 /**
  * Get a slave connection.
  *
  * If no slave connection exist yet, choose one configuration randomly in the
  * read configuration to open it.
  *
  * @param \Propel\Runtime\Adapter\AdapterInterface $adapter
  *
  * @return \Propel\Runtime\Connection\ConnectionInterface
  */
 public function getReadConnection(AdapterInterface $adapter = null)
 {
     if ($this->writeConnection && $this->writeConnection->inTransaction()) {
         return $this->writeConnection;
     }
     if ($this->isForceMasterConnection()) {
         return $this->getWriteConnection($adapter);
     }
     if (null === $this->readConnection) {
         if (null === $this->readConfiguration) {
             $this->readConnection = $this->getWriteConnection($adapter);
         } else {
             $keys = array_keys($this->readConfiguration);
             $key = $keys[mt_rand(0, count($keys) - 1)];
             $configuration = $this->readConfiguration[$key];
             $this->readConnection = ConnectionFactory::create($configuration, $adapter);
             $this->readConnection->setName($this->getName());
         }
     }
     return $this->readConnection;
 }
コード例 #6
0
 /**
  * @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;
 }
コード例 #7
0
ファイル: InitCommand.php プロジェクト: SwissalpS/Propel2
 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;
     }
 }
コード例 #8
0
 /**
  * @expectedException \Propel\Runtime\Exception\PropelException
  */
 public function testCreateFailsWhenPassedAnIncorrectAttributeName()
 {
     $con = ConnectionFactory::create(array('dsn' => 'sqlite::memory:', 'attributes' => array('ATTR_CAE' => PDO::CASE_LOWER)), new SqliteAdapter());
 }
コード例 #9
0
ファイル: SqlManager.php プロジェクト: bondarovich/Propel2
 /**
  * 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;
 }