getConnection() public méthode

Gets the named connection.
public getConnection ( string $name = null ) : Doctrine\DBAL\Connection
$name string The connection name (null for the default one)
Résultat Doctrine\DBAL\Connection
 /**
  * Constructor
  *
  * @param RegistryInterface      $registry
  * @param string                 $class
  * @param RouterInterface        $router
  * @param string                 $routeName
  */
 public function __construct(RegistryInterface $registry, $class, RouterInterface $router, $routeName)
 {
     $tableName = $registry->getManager()->getClassMetadata($class)->table['name'];
     $dql = "SELECT p.id as productId, p.slug as slug,  p.updated_at as lastmod, 'weekly' as changefreq, '0.5' as priority " . "FROM " . $tableName . " p " . "WHERE p.enabled = 1";
     $source = new DoctrineDBALConnectionSourceIterator($registry->getConnection(), $dql);
     $this->iterator = new SymfonySitemapSourceIterator($source, $router, $routeName, array('productId' => null, 'slug' => null));
 }
 /**
  * generate a correct reference number.
  *
  * @param mixed  $object
  * @param string $tableName
  *
  * @throws \Exception
  *
  * @return Exception|string
  */
 protected function generateReference($object, $tableName)
 {
     $date = new \DateTime();
     $sql = sprintf("SELECT count(id) as counter FROM %s WHERE created_at >= '%s' AND reference IS NOT NULL", $tableName, $date->format('Y-m-d'));
     $this->registry->getConnection()->exec(sprintf('LOCK TABLES %s WRITE', $tableName));
     try {
         $statement = $this->registry->getConnection()->query($sql);
         $row = $statement->fetch();
         $reference = sprintf('%02d%02d%02d%06d', $date->format('y'), $date->format('n'), $date->format('j'), $row['counter'] + 1);
         $this->registry->getConnection()->update($tableName, array('reference' => $reference), array('id' => $object->getId()));
         $object->setReference($reference);
     } catch (\Exception $e) {
         $this->registry->getConnection()->exec(sprintf('UNLOCK TABLES'));
         throw $e;
     }
     $this->registry->getConnection()->exec(sprintf('UNLOCK TABLES'));
     return $reference;
 }
 /**
  * Check that the keyword is a reserved word for the database system.
  *
  * @param string $keyword
  *
  * @return boolean
  */
 public function isReservedKeyword($keyword)
 {
     return $this->registry->getConnection()->getDatabasePlatform()->getReservedKeywordsList()->isKeyword($keyword);
 }
Exemple #4
0
 public function releaseLock($lock)
 {
     $connection = $this->registry->getConnection();
     $connection->executeQuery("SELECT RELEASE_LOCK(':lock')", array('lock' => $lock));
     $this->logger->addInfo(sprintf('released named lock "%s"', $lock));
 }