本文整理汇总了PHP中Doctrine\DBAL\Connection类的典型用法代码示例。如果您正苦于以下问题:PHP Connection类的具体用法?PHP Connection怎么用?PHP Connection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Connection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:CATSInformatica,项目名称:CatsSys,代码行数:16,代码来源:AttendanceRepository.php
示例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();
}
开发者ID:hmert,项目名称:importbundle,代码行数:33,代码来源:ImportManager.php
示例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));
}
开发者ID:abacaphiliac,项目名称:doctrine-orm-diagnostics-module,代码行数:11,代码来源:CheckConnection.php
示例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();
}
开发者ID:brodaproject,项目名称:broda,代码行数:14,代码来源:DbalQueryExpressionVisitor.php
示例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;
}
}
开发者ID:janmarek,项目名称:doctrine,代码行数:28,代码来源:ConnectionPanel.php
示例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;
}
}
开发者ID:ekyna,项目名称:commerce,代码行数:39,代码来源:DatabaseTestCase.php
示例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));
}
}
开发者ID:claroline,项目名称:distribution,代码行数:36,代码来源:Updater060300.php
示例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');
}
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:7,代码来源:CompletenessRepositorySpec.php
示例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);
}
开发者ID:WYSAC,项目名称:oregon-owncloud,代码行数:12,代码来源:sqlitemigrator.php
示例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]]);
}
}
开发者ID:glynnforrest,项目名称:active-doctrine,代码行数:7,代码来源:BookshopData.php
示例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);
}
开发者ID:walkeralencar,项目名称:ci-php-analyzer,代码行数:7,代码来源:ArgumentPersister.php
示例12: doExecute
/**
* @param LoggerInterface $logger
* @param bool $dryRun
*/
protected function doExecute(LoggerInterface $logger, $dryRun = false)
{
$duplicateEntitiesQuery = 'SELECT
DISTINCT t2.id
FROM
orocrm_campaign_email_stats AS t1
LEFT JOIN orocrm_campaign_email_stats AS t2
ON t1.email_campaign_id = t2.email_campaign_id
AND t1.marketing_list_item_id = t2.marketing_list_item_id
AND t2.id > t1.id
WHERE t2.id IS NOT NULL';
// Done in 2 queries for cross DB support.
$idsToRemove = array_map(function ($item) {
if (is_array($item) && array_key_exists('id', $item)) {
return $item['id'];
}
return null;
}, $this->connection->fetchAll($duplicateEntitiesQuery));
if ($idsToRemove) {
$query = 'DELETE FROM orocrm_campaign_email_stats WHERE id IN (?)';
$logger->notice($query);
if (!$dryRun) {
$this->connection->executeQuery($query, [$idsToRemove], [Connection::PARAM_INT_ARRAY]);
}
}
}
开发者ID:antrampa,项目名称:crm,代码行数:30,代码来源:AggregateStatisticsQuery.php
示例13: _before
public function _before()
{
$this->connection->exec('DELETE FROM stations');
$loader = new YamlLoader(__DIR__ . '/../../data/fixtures/stations.yml');
$persister = new ConnectionPersister($this->connection);
$persister->persist($loader->load());
}
开发者ID:comphppuebla,项目名称:echale-gas-api,代码行数:7,代码来源:GasStationsCest.php
示例14: __construct
/**
* Creates a new <tt>Statement</tt> for the given SQL and <tt>Connection</tt>.
*
* @param string $sql The SQL of the statement.
* @param \Doctrine\DBAL\Connection $conn The connection on which the statement should be executed.
*/
public function __construct($sql, Connection $conn)
{
$this->sql = $sql;
$this->stmt = $conn->getWrappedConnection()->prepare($sql);
$this->conn = $conn;
$this->platform = $conn->getDatabasePlatform();
}
开发者ID:Dren-x,项目名称:mobit,代码行数:13,代码来源:Statement.php
示例15: processQueueCallback
/**
* ->processQueueCallback(function (\Dja\Db\Model\Metadata $metadata, \Doctrine\DBAL\Schema\Table $table, array $sql, \Doctrine\DBAL\Connection $db) {})
* @param callable|\Closure $callBack
*/
public function processQueueCallback(\Closure $callBack)
{
$callbackQueue = [];
while (count($this->generateQueue)) {
$modelName = array_shift($this->generateQueue);
try {
/** @var Metadata $metadata */
$metadata = $modelName::metadata();
$tblName = $metadata->getDbTableName();
if ($this->db->getSchemaManager()->tablesExist($tblName)) {
continue;
}
if (isset($this->generated[$tblName])) {
continue;
}
$table = $this->metadataToTable($metadata);
$this->generated[$tblName] = 1;
$sql = $this->dp->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES);
array_unshift($callbackQueue, [$metadata, $table, $sql]);
$fks = $table->getForeignKeys();
if (count($fks)) {
$sql = [];
foreach ($fks as $fk) {
$sql[] = $this->dp->getCreateForeignKeySQL($fk, $table);
}
array_push($callbackQueue, [$metadata, $table, $sql]);
}
} catch (\Exception $e) {
pr($e->__toString());
}
}
foreach ($callbackQueue as $args) {
$callBack($args[0], $args[1], $args[2], $this->db);
}
}
开发者ID:buldezir,项目名称:dja_orm,代码行数:39,代码来源:Creation.php
示例16: connect
/**
* Connects to the database.
*
* @return boolean
*/
public function connect()
{
if ($connected = $this->connection->connect()) {
$this->events->dispatch(Events::postConnect, new Event\ConnectionEvent($this));
}
return $connected;
}
开发者ID:jacobjjc,项目名称:PageKit-framework,代码行数:12,代码来源:Connection.php
示例17: setupConfigurationDbal
/**
* setup configuration for Doctrine Dbal.
*
* @param array $db_config array config for override the default configuration.
*/
public function setupConfigurationDbal(array $db_config = [])
{
$dbal_config = new Configuration();
if (empty($db_config)) {
//setup connection configuration.
$config = new SystemConfig();
$config->load('db');
$db_params = $config->get('ALL', 'db');
unset($config, $db_params['table_prefix']);
} else {
$db_params = $db_config;
unset($db_params['table_prefix']);
}
$dbal_config->setSQLLogger(new \System\Libraries\Db\Logger());
try {
$this->Conn = DriverManager::getConnection($db_params, $dbal_config);
$this->Conn->connect();
} catch (\Doctrine\DBAL\DBALException $e) {
http_response_code(500);
echo $e->getMessage();
exit;
}
$this->Conn->setFetchMode(\PDO::FETCH_OBJ);
unset($dbal_config, $db_params);
}
开发者ID:AgniCMS,项目名称:agni-framework,代码行数:30,代码来源:Bootstrap.php
示例18: 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());
}
}
开发者ID:comphppuebla,项目名称:dbal-fixtures,代码行数:11,代码来源:ConnectionPersister.php
示例19: save
public function save(Order $order)
{
$data = $order->jsonSerialize();
unset($data['id']);
$this->connection->insert($this->getTableName(), $data);
$order->setId($this->connection->lastInsertId());
}
开发者ID:Basster,项目名称:hs-bremen-web-api,代码行数:7,代码来源:OrderRepository.php
示例20: shutdown
public function shutdown()
{
if ($this->connection->isTransactionActive()) {
$this->rollback();
}
$this->connection->close();
}
开发者ID:ngydat,项目名称:CoreBundle,代码行数:7,代码来源:TransactionalTestClient.php
注:本文中的Doctrine\DBAL\Connection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论