本文整理汇总了PHP中Doctrine\DBAL\Connection类的典型用法代码示例。如果您正苦于以下问题:PHP Connection类的具体用法?PHP Connection怎么用?PHP Connection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Connection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findStudentAttendances
/**
* Busca as faltas dos tipos $type de todos os alunos atualmente matriculados na turma $schoolClass na data $date.
*
* @param Connection $conn
* @param integer $schoolClass
* @param string $date
* @param integer $type
* @return array
*/
public static function findStudentAttendances(Connection $conn, $schoolClass, $date, $type)
{
$query = $conn->createQueryBuilder();
$sth = $query->select('a.enrollment_id')->from('attendance', 'a')->join('a', 'enrollment', 'e', 'e.enrollment_id = a.enrollment_id')->where('e.enrollment_enddate IS NULL')->andWhere('e.class_id = ?')->andWhere('a.attendance_date = ?')->andWhere('a.attendance_type_id = ?')->setParameters([$schoolClass, $date, $type])->execute();
$list = $sth->fetchAll();
return $list;
}
示例2: singleImport
private function singleImport($config, OutputInterface &$output, $entity_key = null)
{
$this->connection = $this->connectionFactory->createConnection($config['database']);
$this->connection->getConfiguration()->getSQLLogger(null);
if ($entity_key) {
if (!isset($config['maps'][$entity_key])) {
throw new \Exception("Entity alias not found: " . $entity_key);
}
$map = $config['maps'][$entity_key];
if (!$this->container->has($map['old_data']['service_id'])) {
throw new \Exception("Service not exists: " . $map['old_data']['service_id']);
}
$result = $this->importEntity($map);
$output->writeln("<info>Total " . count($result) . " {$entity_key} imported </info>");
} else {
foreach ((array) $config['maps'] as $key => $map) {
if (!$this->container->has($map['old_data']['service_id'])) {
throw new \Exception("Service not exists: " . $map['old_data']['service_id']);
}
$offset = 0;
do {
$result = $this->importEntity($map);
$output->writeln("<info>Total " . count($result) . " {$key} imported </info>");
if (!$result) {
break;
}
$offset++;
$this->setOffset($offset);
} while (true);
}
}
$this->connection->close();
}
示例3: checkStandardConnection
/**
* @param Connection $connection
* @return Success|Failure
*/
private function checkStandardConnection(Connection $connection)
{
if ($connection->ping()) {
return new Success(get_class($connection));
}
return new Failure(get_class($connection));
}
示例4: __construct
/**
* Construtor
*
* @param Connection $connection
* @param array $rootAliases
* @param array $fieldMap
*/
public function __construct(Connection $connection, array $rootAliases, array $fieldMap = array())
{
$this->rootAliases = $rootAliases;
$this->fieldMap = $fieldMap;
$this->conn = $connection;
$this->expr = $this->conn->getExpressionBuilder();
}
示例5: stopQuery
public function stopQuery()
{
if ($this->explainRunning) {
return;
}
$keys = array_keys($this->queries);
$key = end($keys);
$this->queries[$key][self::TIME] = Debugger::timer('doctrine');
$this->totalTime += $this->queries[$key][self::TIME];
// get EXPLAIN for SELECT queries
if ($this->doExplains) {
if ($this->connection === NULL) {
throw new \Nette\InvalidStateException('You must set a Doctrine\\DBAL\\Connection to get EXPLAIN.');
}
$query = $this->queries[$key][self::SQL];
if (strtoupper(substr(ltrim($query), 0, 6)) !== 'SELECT') {
// only SELECTs are supported
return;
}
// prevent logging explains & infinite recursion
$this->explainRunning = TRUE;
$params = $this->queries[$key][self::PARAMS];
$types = $this->queries[$key][self::TYPES];
$stmt = $this->connection->executeQuery('EXPLAIN ' . $query, $params, $types);
$this->queries[$key][self::EXPLAIN] = $stmt->fetchAll();
$this->explainRunning = FALSE;
}
}
示例6: setUp
/**
* Initializes the database (once).
*
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\Tools\ToolsException
*/
protected function setUp()
{
if (null === static::$_conn) {
$dbPath = __DIR__ . '/../../../db.sqlite';
if (file_exists($dbPath)) {
unlink($dbPath);
}
$params = ['driver' => 'pdo_sqlite', 'path' => $dbPath];
static::$_conn = DriverManager::getConnection($params);
static::$_conn->getConfiguration()->setSQLLogger(null);
}
if (null === static::$_em) {
$paths = [__DIR__ . '/../../../../../src/Ekyna/Commerce/Bridge/Doctrine/ORM/Resources/mapping'];
$isDevMode = true;
$config = Setup::createXMLMetadataConfiguration($paths, $isDevMode);
$em = EntityManager::create(static::$_conn, $config);
$classes = [];
foreach (static::$_classes as $class) {
array_push($classes, $em->getClassMetadata($class));
}
$schemaTool = new SchemaTool($em);
$schemaTool->dropSchema($classes);
$schemaTool->createSchema($classes);
// Load fixtures
$loader = new Loader();
$loader->loadFromDirectory(__DIR__ . '/../../../../../src/Ekyna/Commerce/Bridge/Doctrine/Fixtures');
$purger = new ORMPurger();
$executor = new ORMExecutor($em, $purger);
$executor->execute($loader->getFixtures());
static::$_em = $em;
}
}
示例7: migrateBadgeTables
/**
* @param Connection $connection
* @param AppKernel $kernel
*
* @throws \Claroline\MigrationBundle\Migrator\InvalidDirectionException
* @throws \Claroline\MigrationBundle\Migrator\InvalidVersionException
* @throws \Doctrine\DBAL\Migrations\MigrationException
*/
protected function migrateBadgeTables(Connection $connection, AppKernel $kernel)
{
$portfolioBundle = $this->container->get('claroline.persistence.object_manager')->getRepository('ClarolineCoreBundle:Plugin')->findBy(array('vendorName' => 'Icap', 'bundleName' => 'PortfolioBundle'));
$portfolioBundle = count($portfolioBundle) === 1 ? true : false;
if (!$portfolioBundle && $connection->getSchemaManager()->tablesExist(['icap__portfolio_widget_badges'])) {
$this->log('Deleting portfolios badges tables...');
$connection->getSchemaManager()->dropTable('icap__portfolio_widget_badges_badge');
$connection->getSchemaManager()->dropTable('icap__portfolio_widget_badges');
$this->log('Portfolios badges tables deleted.');
}
if ($portfolioBundle && !$connection->getSchemaManager()->tablesExist(['icap__portfolio_widget_badges'])) {
$badgeBundle = $kernel->getBundle('IcapBadgeBundle');
$this->log('Executing migrations for portfolio interaction');
$migrationsDir = "{$badgeBundle->getPath()}/Installation/Migrations";
$migrationsName = "{$badgeBundle->getName()} migration";
$migrationsNamespace = "{$badgeBundle->getNamespace()}\\Installation\\Migrations";
$migrationsTableName = 'doctrine_' . strtolower($badgeBundle->getName()) . '_versions';
$config = new Configuration($connection);
$config->setName($migrationsName);
$config->setMigrationsDirectory($migrationsDir);
$config->setMigrationsNamespace($migrationsNamespace);
$config->setMigrationsTableName($migrationsTableName);
$config->registerMigrationsFromDirectory($migrationsDir);
$migration = new Migration($config);
$executedQueriesNumber = $migration->migrate('20150929141509');
$this->log(sprintf('%d queries executed', $executedQueriesNumber));
}
}
示例8: let
function let(EntityManager $manager, Connection $connection, Statement $statement, ClassMetadata $classMetadata)
{
$connection->prepare(Argument::any())->willReturn($statement);
$manager->getClassMetadata(Argument::any())->willReturn($classMetadata);
$manager->getConnection()->willReturn($connection);
$this->beConstructedWith($manager, 'pim_product_class');
}
示例9: getDiff
/**
* @param Schema $targetSchema
* @param \Doctrine\DBAL\Connection $connection
* @return \Doctrine\DBAL\Schema\SchemaDiff
*/
protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection)
{
$platform = $connection->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('tinyint unsigned', 'integer');
$platform->registerDoctrineTypeMapping('smallint unsigned', 'integer');
return parent::getDiff($targetSchema, $connection);
}
示例10: loadAuthors
protected function loadAuthors(Connection $connection)
{
$records = [['Thomas Hardy'], ['Terry Pratchett'], ['Malcolm Gladwell'], ['Charles Dickens']];
foreach ($records as $r) {
$connection->insert('authors', ['name' => $r[0]]);
}
}
示例11: __construct
public function __construct(Connection $con)
{
$this->con = $con;
$this->platform = $con->getDatabasePlatform();
$this->phpType = Type::getType(PhpTypeType::NAME);
$this->insertStmt = $con->prepare(self::INSERT_SQL);
}
示例12: insertTableRows
/**
* @param string $tableName
* @param array $rows
*/
protected function insertTableRows($tableName, array $rows)
{
foreach ($rows as $rowKey => $values) {
$this->connection->insert($tableName, $this->parser->parse($values));
$this->parser->addReference($rowKey, $this->connection->lastInsertId());
}
}
示例13: save
public function save(Order $order)
{
$data = $order->jsonSerialize();
unset($data['id']);
$this->connection->insert($this->getTableName(), $data);
$order->setId($this->connection->lastInsertId());
}
示例14: shutdown
public function shutdown()
{
if ($this->connection->isTransactionActive()) {
$this->rollback();
}
$this->connection->close();
}
示例15: fetch
/**
* @param QueryInterface $query
* @return array
*/
public function fetch(QueryInterface $query)
{
$query->checkReplacements();
$plainQuery = $query->getPlainQuery();
list($parameters, $plainQuery) = $this->modifyParametersFromArrayToScalar($query->getParameters(), $plainQuery);
return $this->connection->fetchAll($plainQuery, $parameters);
}