本文整理汇总了PHP中Doctrine\Bundle\DoctrineBundle\Registry::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP Registry::getConnection方法的具体用法?PHP Registry::getConnection怎么用?PHP Registry::getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Bundle\DoctrineBundle\Registry
的用法示例。
在下文中一共展示了Registry::getConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->doctrine = $this->getContainer()->get('doctrine');
// get all cities
$qb = $this->doctrine->getManager()->createQueryBuilder();
$qb->select('ct')->from('HelperBundle:City', 'ct')->where('ct.geoCityId IS NOT NULL')->orderBy('ct.id', 'ASC');
$cities = $qb->getQuery()->getResult();
$connection = $this->doctrine->getConnection();
foreach ($cities as $city) {
$output->write('Updating data of old city #' . $city->getId());
$sql = "SELECT cg_gct.* FROM `chromedia_global`.`geo_cities` cg_gct WHERE cg_gct.`id` = ?";
$statement = $connection->prepare($sql);
$statement->bindValue(1, $city->getGeoCityId());
$statement->execute();
$globalCityData = $statement->fetch();
if ($globalCityData) {
$updateSql = "UPDATE `cities` SET `id` = :geoCityId, `name` = :geoCityName, `slug` = :geoCitySlug WHERE `old_id` = :oldId";
$updateStatement = $connection->prepare($updateSql);
$updateStatement->bindValue('geoCityId', $globalCityData['id']);
$updateStatement->bindValue('geoCityName', $globalCityData['name']);
$updateStatement->bindValue('geoCitySlug', $globalCityData['slug']);
$updateStatement->bindValue('oldId', $city->getOldId());
$updateStatement->execute();
$output->writeln(' OK');
} else {
$output->writeln(' Not found');
}
}
}
示例2: __construct
/**
* @param \Doctrine\Bundle\DoctrineBundle\Registry $doctrine
*/
public function __construct($doctrine)
{
$dbConfig = $doctrine->getConnection()->getParams();
if (isset($dbConfig['dsn'])) {
$data = EhrlichAndreas_Util_Dsn::parseDsn($dbConfig['dsn']);
foreach ($data as $key => $value) {
$dbConfig[$key] = $value;
}
$data = EhrlichAndreas_Util_Dsn::parseUri($dbConfig['dsn']);
if (isset($data[0])) {
$dbConfig['adapter'] = ucfirst($data[0]);
}
if (isset($dbConfig['adapter']) && $dbConfig['driver']) {
$dbConfig['adapter'] = $dbConfig['driver'] . '_' . $dbConfig['adapter'];
}
}
if (!isset($dbConfig['adapter']) && isset($dbConfig['driver'])) {
$dbConfig['adapter'] = $dbConfig['driver'];
unset($dbConfig['driver']);
}
if (!isset($dbConfig['driver_options']) && isset($dbConfig['driverOptions'])) {
$dbConfig['driver_options'] = $dbConfig['driverOptions'];
unset($dbConfig['driverOptions']);
}
if (!isset($dbConfig['username']) && isset($dbConfig['user'])) {
$dbConfig['username'] = $dbConfig['user'];
unset($dbConfig['user']);
}
$this->adapter = EhrlichAndreas_Db_Db::factory($dbConfig);
$this->adapter->setConnection($doctrine->getConnection()->getWrappedConnection());
}
示例3: reset
private function reset()
{
if ($this->doctrine) {
/** @var Connection $c */
$c = $this->doctrine->getConnection();
$c->close();
$this->doctrine->resetManager();
}
}
示例4: __construct
/**
* @param \Doctrine\Bundle\DoctrineBundle\Registry $doctrine
* @param \Symfony\Bridge\Monolog\Logger $logger
*/
public function __construct(Doctrine $doctrine, Logger $logger)
{
$this->entityManager = $doctrine->getManager();
$dLogger = new \Doctrine\DBAL\Logging\DebugStack();
$doctrine->getConnection()->getConfiguration()->setSQLLogger($dLogger);
$logger->info(json_encode($dLogger->queries));
}
示例5: mergeTreatmentToAnotherTreatment
/**
* Merge $fromTreatment to $toTreatment
*
* @param Treatment $fromTreatment
* @param Treatment $toTreatment
*/
public function mergeTreatmentToAnotherTreatment(Treatment $fromTreatment, Treatment $toTreatment)
{
/***
* Steps for merge
* 1. Move all institution_treatments of $fromTreatment to $toTreatment. Considerations:
* a. Consider existing institution_treatments.institution_id and institution_treatments.toTreatment combination
* 2. Delete $fromTreatment
*/
$connection = $this->doctrine->getConnection();
$em = $this->doctrine->getManager();
// step 1
$sql = "UPDATE IGNORE `institution_treatments` inst_tr \n SET inst_tr.`treatment_id` = :toTreatmentId\n WHERE inst_tr.`treatment_id` = :fromTreatmentId";
$statement = $connection->prepare($sql);
$statement->bindValue('fromTreatmentId', $fromTreatment->getId());
$statement->bindValue('toTreatmentId', $toTreatment->getId());
$statement->execute();
// remove the remaining institutions $fromTreatment with existing $toTreatment that were left out from the above operation
$sql = "DELETE FROM `institution_treatments` WHERE `treatment_id` = :fromTreatmentId";
$statement = $connection->prepare($sql);
$statement->bindValue('fromTreatmentId', $fromTreatment->getId());
$statement->execute();
// step 2
// remove $fromTreatment
$em->remove($fromTreatment);
$em->flush();
}
示例6: testGetUnknownConnection
public function testGetUnknownConnection()
{
$container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$registry = new Registry($container, array(), array(), 'default', 'default');
$this->setExpectedException('InvalidArgumentException', 'Doctrine ORM Connection named "default" does not exist.');
$registry->getConnection('default');
}
示例7: doInstitution
private function doInstitution(Institution $institution, $em)
{
//$this->output->write("Institution #{$institution->getId()}");
$oldState = \trim($institution->getStateBak());
if ($oldState == '') {
//$this->output->writeln('[No old state]');
return;
}
$country = $institution->getCountry();
// find a state with the same name for this country in chromedia_global
$connection = $this->doctrine->getConnection();
$sql = "SELECT gs.* FROM `chromedia_global`.`geo_states` gs WHERE `name` LIKE :state AND `geo_country_id` = :geoCountryId";
$statement = $connection->prepare($sql);
$statement->bindValue('state', $oldState);
$statement->bindValue('geoCountryId', $country->getId());
$statement->execute();
if (!($rowCount = $statement->rowCount())) {
//$this->output->writeln('[No matching state]');
$this->nonMatchingInstitutions[] = $institution;
return;
} else {
if ($rowCount == 1) {
$globalStateData = $statement->fetch();
$hcaState = $this->getHcaState($globalStateData, $country);
$institution->setState($hcaState);
$em->persist($institution);
//$this->output->writeln("[Set to {$hcaState->getName()} ]");
} else {
if (strtolower($oldState) == 'singapore') {
// manual for singapore
while ($globalStateData = $statement->fetch()) {
if ($globalStateData['id'] == 2732) {
$hcaState = $this->getHcaState($globalStateData, $country);
$institution->setState($hcaState);
$em->persist($institution);
//$this->output->writeln("[Set to {$hcaState->getName()} ]");
break;
}
}
} else {
$this->nonUniqueStates[] = array('country_id' => $country->getId(), 'state' => $oldState);
//$this->output->writeln("[Non unique state {$oldState}]");
$this->nonMatchingInstitutions[] = $institution;
}
}
}
}
示例8: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->doctrine = $this->getContainer()->get('doctrine');
$this->om = $this->doctrine->getManager();
$this->connection = $this->doctrine->getConnection();
$this->output = $output;
$this->termRepository = $this->doctrine->getRepository('TermBundle:Term');
// reset internal flag to 0 for terms linked to a treatment
$this->resetInternalFlagOfTermsWithTreatmentTypeDocuments();
// get all treatments
$qb = $this->doctrine->getManager()->createQueryBuilder();
$qb->select('t1')->from('TreatmentBundle:Treatment', 't1')->orderBy('t1.name', 'ASC');
$treatments = $qb->getQuery()->getResult();
foreach ($treatments as $treatment) {
$this->cleanupTerms($treatment);
}
$this->om->flush();
}
示例9: updateEmail
private function updateEmail($accountId, $accountEmail, $contactEmail)
{
$updateSql = "UPDATE `chromedia_global`.`accounts` SET `email` = :contactEmail WHERE `id` = :accountId AND `email` = :accountEmail";
$statement = $this->doctrine->getConnection()->prepare($updateSql);
$statement->bindValue('accountId', $accountId);
$statement->bindvalue('accountEmail', $accountEmail);
$statement->bindValue('contactEmail', $contactEmail);
$statement->execute();
}
开发者ID:TMBaay,项目名称:MEDTrip---Healthcareabroad,代码行数:9,代码来源:PopulateInstitutionAccountOwnerEmailCommand.php
示例10: __construct
/**
* @param Registry $doctrine
* @param Selector $selector
*/
public function __construct(Registry $doctrine, Selector $selector)
{
$this->repository = $doctrine->getRepository('AnimeDbCatalogBundle:Item');
$this->selector = $selector;
// register custom lower()
$conn = $doctrine->getConnection()->getWrappedConnection();
if (method_exists($conn, 'sqliteCreateFunction')) {
$conn->sqliteCreateFunction('lower', function ($str) {
return mb_strtolower($str, 'UTF8');
}, 1);
}
}
示例11: __construct
/**
* @param Registry $registry
* @param \Knp\Component\Pager\Paginator $paginator
* @param $connection
* @param $manager
* @param $itemsPerPage
* @internal param $items
*/
public function __construct(Registry $registry, Paginator $paginator, $connection, $manager, $itemsPerPage)
{
$this->registry = $registry;
$this->paginator = $paginator;
$this->itemsPerPage = $itemsPerPage;
// this prevents a 'NULL not support' exception
if (!$connection || empty($connection)) {
$connection = null;
}
$this->connection = $registry->getConnection($connection);
if (!$manager || empty($manager)) {
$manager = null;
}
$this->manager = $registry->getManager($manager);
}
示例12: run
/**
* @param string $connectionName
* @param string $mysqlHost
* @param string $mysqlUsername
* @param string $mysqlPassword
* @param string $mysqlDbname
* @param array $onlyTables
*/
public function run(string $connectionName = 'default', string $mysqlHost = 'localhost', string $mysqlUsername = null, string $mysqlPassword = null, string $mysqlDbname = null, array $onlyTables = [])
{
$this->connection = $this->doctrine->getConnection($connectionName);
if ($mysqlHost) {
$this->initMysqlSettings($mysqlHost, $mysqlUsername, $mysqlPassword, $mysqlDbname);
}
$tables = $this->showTables();
foreach ($tables as $tableName) {
$this->fs->remove([self::DUMP_IN_FILE_NAME, self::DUMP_OUT_FILE_NAME]);
if (!empty($onlyTables) && !in_array($tableName, $onlyTables)) {
continue;
}
$this->dumpTableIntoFile($tableName);
$this->convertTextInFile(self::DUMP_IN_FILE_NAME);
$this->restoreFromFile(self::DUMP_OUT_FILE_NAME);
}
}
示例13: execute
/**
* Execute the command. Get all the deposits needing to be harvested. Each
* deposit will be passed to the commands processDeposit() function.
*
* @param InputInterface $input
* @param OutputInterface $output
*/
protected final function execute(InputInterface $input, OutputInterface $output)
{
$force = $input->getOption('force');
$this->em->getConnection()->getConfiguration()->setSQLLogger(null);
$q = $this->em->createQuery('SELECT d FROM AppBundle\\Entity\\Deposit d where d.plnState = :state');
$q->setParameter('state', 'agreement');
$iterator = $q->iterate();
$i = 0;
foreach ($iterator as $row) {
$deposit = $row[0];
$this->processDeposit($deposit, $force);
$i++;
if ($i % 50 === 0) {
$this->em->clear();
gc_collect_cycles();
}
}
}
示例14: setDoctrine
public function setDoctrine(Registry $doctrine)
{
$this->doctrine = $doctrine;
$this->connection = $doctrine->getConnection('hca_blog');
}
示例15: enableUserTriggers
/**
* @param Table $table
*/
private function enableUserTriggers(Table $table)
{
$tableFullName = $table->getSchema() . PgAnalyzer::DB_SEPARATOR . $table->getName();
$sql = "ALTER TABLE " . $tableFullName . " ENABLE TRIGGER USER";
$this->doctrine->getConnection($this->parameters->getManagerTo())->executeQuery($sql);
}