• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP DBAL\DriverManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Doctrine\DBAL\DriverManager的典型用法代码示例。如果您正苦于以下问题:PHP DriverManager类的具体用法?PHP DriverManager怎么用?PHP DriverManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了DriverManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: getSpecifiedConnectionParams

 private static function getSpecifiedConnectionParams()
 {
     $realDbParams = self::getParamsForMainConnection();
     if (!self::$initialized) {
         $tmpDbParams = self::getParamsForTemporaryConnection();
         $realConn = DriverManager::getConnection($realDbParams);
         // Connect to tmpdb in order to drop and create the real test db.
         $tmpConn = DriverManager::getConnection($tmpDbParams);
         $platform = $tmpConn->getDatabasePlatform();
         if ($platform->supportsCreateDropDatabase()) {
             $dbname = $realConn->getDatabase();
             $realConn->close();
             $tmpConn->getSchemaManager()->dropAndCreateDatabase($dbname);
             $tmpConn->close();
         } else {
             $sm = $realConn->getSchemaManager();
             $schema = $sm->createSchema();
             $stmts = $schema->toDropSql($realConn->getDatabasePlatform());
             foreach ($stmts as $stmt) {
                 $realConn->exec($stmt);
             }
         }
         self::$initialized = true;
     }
     return $realDbParams;
 }
开发者ID:selimcr,项目名称:servigases,代码行数:26,代码来源:TestUtil.php


示例2: getEntityManagerInstanceMock

 /**
  * Just for internal use, could be overridden in child classes
  * User $em property in case if you need EntityManager
  *
  * @return EntityManagerMock
  */
 protected function getEntityManagerInstanceMock()
 {
     $this->config = Setup::createAnnotationMetadataConfiguration(array('./Fixtures'), true);
     $this->config->setQuoteStrategy(new QuotingStrategy());
     $conn = array('driverClass' => 'Luxifer\\Tests\\Mocks\\DriverMock', 'wrapperClass' => 'Luxifer\\Tests\\Mocks\\ConnectionMock', 'user' => 'john', 'password' => 'wayne');
     $conn = DriverManager::getConnection($conn, $this->config);
     $this->config->setProxyDir(__DIR__ . '/Proxies');
     $this->config->setProxyNamespace('Luxifer\\Tests\\Proxies');
     $this->config->addCustomDatetimeFunction('date', 'Luxifer\\DQL\\Datetime\\Date');
     $this->config->addCustomDatetimeFunction('datediff', 'Luxifer\\DQL\\Datetime\\DateDiff');
     $this->config->addCustomDatetimeFunction('day', 'Luxifer\\DQL\\Datetime\\Day');
     $this->config->addCustomDatetimeFunction('dayofmonth', 'Luxifer\\DQL\\Datetime\\DayOfMonth');
     $this->config->addCustomDatetimeFunction('week', 'Luxifer\\DQL\\Datetime\\Week');
     $this->config->addCustomDatetimeFunction('dayofweek', 'Luxifer\\DQL\\Datetime\\DayOfWeek');
     $this->config->addCustomDatetimeFunction('dayofyear', 'Luxifer\\DQL\\Datetime\\DayOfYear');
     $this->config->addCustomDatetimeFunction('hour', 'Luxifer\\DQL\\Datetime\\Hour');
     $this->config->addCustomDatetimeFunction('minute', 'Luxifer\\DQL\\Datetime\\Minute');
     $this->config->addCustomDatetimeFunction('month', 'Luxifer\\DQL\\Datetime\\Month');
     $this->config->addCustomDatetimeFunction('quarter', 'Luxifer\\DQL\\Datetime\\Quarter');
     $this->config->addCustomDatetimeFunction('second', 'Luxifer\\DQL\\Datetime\\Second');
     $this->config->addCustomDatetimeFunction('time', 'Luxifer\\DQL\\Datetime\\Time');
     $this->config->addCustomDatetimeFunction('year', 'Luxifer\\DQL\\Datetime\\Year');
     $this->config->addCustomDatetimeFunction('convert_tz', 'Luxifer\\DQL\\Datetime\\ConvertTZ');
     $this->config->addCustomDatetimeFunction('date_format', 'Luxifer\\DQL\\Datetime\\DateFormat');
     $this->config->addCustomDatetimeFunction('concat_ws', 'Luxifer\\DQL\\String\\ConcatWs');
     return EntityManagerMock::create($conn, $this->config);
 }
开发者ID:sketchthat,项目名称:doctrine-functions,代码行数:33,代码来源:DQLFunctionTest.php


示例3: connectDatabase

 private function connectDatabase(OutputInterface $output)
 {
     $param = array();
     $param['host'] = $this->dialog->ask($output, '<question>Where is your database server? [localhost]</question> ', 'localhost');
     $param['user'] = $this->dialog->ask($output, '<question>What is your database username? [root]</question> ', 'root');
     $param['password'] = $this->dialog->ask($output, '<question>What is your database password?</question> ', '');
     $param['driver'] = 'pdo_mysql';
     // Save dbName for later use to create database
     $this->dbName = $this->dialog->ask($output, '<question>What is your database name? [BungaWire]</question> ', 'BungaWire');
     $output->writeln('');
     // Write empty line for easy read
     $config = new Configuration();
     $this->dbConnection = DriverManager::getConnection($param, $config);
     $this->dbConnection->connect();
     if ($this->dbConnection->isConnected() === false) {
         $output->writeln('Database connection failed, please check your setting');
         $output->writeln('You connection configuration is:');
         $output->writeln('host: ' . $param['host']);
         $output->writeln('user: ' . $param['user']);
         $output->writeln('password: ' . $param['password']);
         $output->writeln('Database Name: ' . $param['dbname']);
         $output->writeln('Driver: ' . $param['driver']);
         $output->writeln($this->dbConnection->errorInfo());
         $output->writeln('Please try again!');
         $this->connectDatabase($output);
     } else {
         $output->writeln('Database connected!');
     }
 }
开发者ID:gusdecool,项目名称:bunga-wire,代码行数:29,代码来源:InstallRun.php


示例4: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $database = array();
     if (extension_loaded('pdo_pgsql')) {
         $database['pdo_pgsql'] = 'PostgreSQL';
     }
     if (extension_loaded('pdo_mysql')) {
         $database['pdo_mysql'] = 'MySQL';
     }
     if (extension_loaded('pdo_sqlite')) {
         $database['pdo_sqlite'] = 'SQLite(開発者用)';
     }
     $builder->add('database', 'choice', array('label' => 'データベースの種類', 'choices' => $database, 'expanded' => false, 'multiple' => false, 'constraints' => array(new Assert\NotBlank())))->add('database_host', 'text', array('label' => 'データベースのホスト名', 'required' => false))->add('database_port', 'text', array('label' => 'ポート番号', 'required' => false))->add('database_name', 'text', array('label' => 'データベース名', 'constraints' => array(new Assert\Callback(array($this, 'validate')))))->add('database_user', 'text', array('label' => 'ユーザ名', 'constraints' => array(new Assert\Callback(array($this, 'validate')))))->add('database_password', 'password', array('label' => 'パスワード', 'required' => false))->addEventListener(FormEvents::POST_SUBMIT, function ($event) {
         $form = $event->getForm();
         $data = $form->getData();
         try {
             $config = new \Doctrine\DBAL\Configuration();
             if ($data['database'] == 'pdo_sqlite') {
                 $connectionParams = array('driver' => $data['database'], 'path' => __DIR__ . '/../../../../../app/config/eccube/eccube.db');
             } else {
                 $connectionParams = array('dbname' => $data['database_name'], 'user' => $data['database_user'], 'password' => $data['database_password'], 'host' => $data['database_host'], 'driver' => $data['database'], 'port' => $data['database_port']);
             }
             // todo MySQL, PostgreSQLのバージョンチェックも欲しい.DBALで接続すればエラーになる?
             $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
             $conn->connect();
         } catch (\Exception $e) {
             $form['database']->addError(new FormError('データベースに接続できませんでした。' . $e->getMessage()));
         }
     });
 }
开发者ID:ryo-endo,项目名称:ec-cube,代码行数:33,代码来源:Step4Type.php


示例5: createDatabase

 protected static function createDatabase()
 {
     if (empty(getenv('PGSQL_HOST')) && file_exists(__DIR__ . '/../../.env')) {
         $dotenv = new Dotenv(__DIR__ . '/../../');
         $dotenv->load();
     }
     if (empty(getenv('PGSQL_HOST')) || empty(getenv('PGSQL_USER'))) {
         throw new \RuntimeException('Create a .env file with PGSQL_HOST, PGSQL_USER, and PGSQL_PASS to run this test.');
     }
     $pass = getenv('PGSQL_PASS') ? getenv('PGSQL_PASS') : '';
     $pdo = new \PDO('pgsql:host=' . getenv('PGSQL_HOST'), getenv('PGSQL_USER'), $pass);
     $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     self::$connection = DriverManager::getConnection(['driver' => 'pdo_pgsql', 'pdo' => $pdo, 'dbname' => 'public']);
     self::$connection->query('drop schema public cascade');
     self::$connection->query('create schema public');
     self::$connection->query('CREATE TABLE extended_data_objects (
       id SERIAL PRIMARY KEY,
       "isDeleted" BOOLEAN NOT NULL DEFAULT FALSE,
       "myColumn" VARCHAR(255) NOT NULL,
       "myNullableColumn" INT NULL DEFAULT NULL,
       "otherDataObjectId" INT NULL
     )');
     self::$connection->query('CREATE TABLE other_data_objects (
       id SERIAL PRIMARY KEY,
       "isDeleted" BOOLEAN NOT NULL DEFAULT FALSE,
       "name" VARCHAR(255) NOT NULL,
       "extendedDataObjectId" INT NULL REFERENCES extended_data_objects (id)
     )');
     self::$connection->query('CREATE TABLE extended_other_rel (
       "extendedDataObjectId" INT NOT NULL REFERENCES extended_data_objects (id),
       "otherDataObjectId" INT NOT NULL REFERENCES other_data_objects (id)
     )');
 }
开发者ID:thewunder,项目名称:corma,代码行数:33,代码来源:PostgresIntegrationTest.php


示例6: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::SQLITE_PATH], new Configuration());
     $config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/../..'], true);
     $this->entityManager = EntityManager::create($this->connection, $config);
 }
开发者ID:alexdpy,项目名称:acl,代码行数:7,代码来源:DoctrineOrmAclFilterTest.php


示例7: instance

 /**
  * 单例模式,获取一个指定的实例
  *
  *     // 加载默认实例
  *     $db = Database::instance();
  *
  *     // 指定实例名称和配置
  *     $db = Database::instance('custom', $config);
  *
  * @param  string $name   实例名
  * @param  array  $config 配置参数
  * @return Connection
  */
 public static function instance($name = null, array $config = null)
 {
     if (null === $name) {
         $name = Db::$default;
     }
     if (!isset(Db::$instances[$name])) {
         // 读取配置
         if (null === $config) {
             $config = (array) Config::load(self::$configFile)->get($name);
             Base::getLog()->debug(__METHOD__ . ' get default config', ['name' => $name]);
         }
         // 合并默认配置
         if (isset(self::$defaultConfig[Arr::get($config, 'driver')])) {
             $config = Arr::merge(self::$defaultConfig[Arr::get($config, 'driver')], $config);
             Base::getLog()->debug(__METHOD__ . ' merge config', ['name' => $name]);
         }
         $conn = DriverManager::getConnection($config);
         Base::getLog()->debug(__METHOD__ . ' create dbal connection', ['name' => $name]);
         // 额外注册字段类型
         if (isset(self::$mappingType[Arr::get($config, 'driver')])) {
             $platform = $conn->getDatabasePlatform();
             foreach (self::$mappingType[Arr::get($config, 'driver')] as $dbType => $doctrineType) {
                 if (!$platform->hasDoctrineTypeMappingFor($dbType)) {
                     Base::getLog()->debug(__METHOD__ . ' add dbal mapping type', ['raw' => $dbType, 'dbal' => $doctrineType]);
                     $platform->registerDoctrineTypeMapping($dbType, $doctrineType);
                 }
             }
         }
         Db::$instances[$name] = $conn;
         Base::getLog()->debug(__METHOD__ . ' save db instance', ['name' => $name]);
     }
     return Db::$instances[$name];
 }
开发者ID:tourze,项目名称:db,代码行数:46,代码来源:Db.php


示例8: addConnection

 /**
  * Add database connection
  *
  * @param string  $name   Unique name for the connection
  * @param string  $dsn    DSN string for this connection
  * @param boolean $defaut Use this connection as the default? The first connection added is automatically set as the default, even if this flag is false.
  *
  * @return \Doctrine\DBAL\Connection
  * @throws \Spot\Exception
  */
 public function addConnection($name, $dsn, $default = false)
 {
     // Connection name must be unique
     if (isset($this->_connections[$name])) {
         throw new Exception("Connection for '" . $name . "' already exists. Connection name must be unique.");
     }
     if ($dsn instanceof DBAL\Connection) {
         $connection = $dsn;
     } else {
         if (is_array($dsn)) {
             $connectionParams = $dsn;
         } else {
             $connectionParams = $this->parseDsn($dsn);
             if ($connectionParams === false) {
                 throw new Exception("Unable to parse given DSN string");
             }
         }
         $config = new DBAL\Configuration();
         $connection = DBAL\DriverManager::getConnection($connectionParams, $config);
     }
     // Set as default connection?
     if (true === $default || null === $this->_defaultConnection) {
         $this->_defaultConnection = $name;
     }
     // Store connection and return adapter instance
     $this->_connections[$name] = $connection;
     return $connection;
 }
开发者ID:keodev,项目名称:dev-project-paragliding,代码行数:38,代码来源:Config.php


示例9: setUp

 protected function setUp()
 {
     $this->app = $app = new Container();
     $db_config = ['driver' => 'pdo_sqlite', 'dbname' => 'sqlite:///:memory:'];
     $models = ['post.model' => function () use($app) {
         return new Post($app);
     }, 'comment.model' => 'Comment'];
     $app['db'] = function () use($db_config) {
         $db = \Doctrine\DBAL\DriverManager::getConnection($db_config);
         $sql = file_get_contents(codecept_data_dir() . '/dump.sql');
         $db->exec($sql);
         return $db;
     };
     foreach ($models as $name => $class) {
         if (is_callable($class)) {
             $callable = $class;
         } else {
             $callable = function () use($class, $app) {
                 return new $class($app);
             };
         }
         $app[$name] = $app->factory($callable);
     }
     $this->loadFixtures();
 }
开发者ID:arduanov,项目名称:pimple-active-record,代码行数:25,代码来源:RecordTest.php


示例10: execute

 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $connection = $this->getDoctrineConnection($input->getOption('connection'));
     $params = $connection->getParams();
     if (isset($params['master'])) {
         $params = $params['master'];
     }
     $name = isset($params['path']) ? $params['path'] : (isset($params['dbname']) ? $params['dbname'] : false);
     if (!$name) {
         throw new \InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be dropped.");
     }
     unset($params['dbname']);
     $tmpConnection = DriverManager::getConnection($params);
     // Only quote if we don't have a path
     if (!isset($params['path'])) {
         $name = $tmpConnection->getDatabasePlatform()->quoteSingleIdentifier($name);
     }
     $error = false;
     try {
         $tmpConnection->getSchemaManager()->createDatabase($name);
         $output->writeln(sprintf('<info>Created database for connection named <comment>%s</comment></info>', $name));
     } catch (\Exception $e) {
         $output->writeln(sprintf('<error>Could not create database for connection named <comment>%s</comment></error>', $name));
         $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
         $error = true;
     }
     $tmpConnection->close();
     return $error ? 1 : 0;
 }
开发者ID:MTyassine,项目名称:jciperformsystem,代码行数:32,代码来源:CreateDatabaseDoctrineCommand.php


示例11: getDBAL

 public function getDBAL($conn = 'default')
 {
     if (in_array($conn, self::$dbal_conns)) {
         return self::$dbal_conns[$conn];
     }
     return self::$dbal_conns[$conn] = \Doctrine\DBAL\DriverManager::getConnection($this->getConnection($conn), new \Doctrine\DBAL\Configuration());
 }
开发者ID:phpcodebooster,项目名称:package,代码行数:7,代码来源:DoctrineService.php


示例12: initDb

 public function initDb()
 {
     $params = $this->connection->getParams();
     $name = $params['dbname'];
     unset($params['dbname']);
     $conn = DriverManager::getConnection($params);
     $conn->exec('CREATE DATABASE IF NOT EXISTS ' . $name);
     $conn->exec('USE ' . $name);
     $conn->exec('CREATE TABLE IF NOT EXISTS bl_run (
         id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
         title VARCHAR(64),
         project_name VARCHAR(64) NOT NULL,
         properties TEXT NOT NULL,
         created_at DATETIME NOT NULL
     )');
     $conn->exec('CREATE TABLE IF NOT EXISTS bl_run_unit (
         id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
         run_id INTEGER NOT NULL,
         feature TEXT NOT NULL,
         created_at DATETIME NOT NULL,
         started_at DATETIME,
         finished_at DATETIME,
         return_code INTEGER,
         output_files TEXT
     )');
 }
开发者ID:alexandresalome,项目名称:behat-launcher,代码行数:26,代码来源:MysqlStorage.php


示例13: getDbal

 /**
  * @return \Doctrine\DBAL\Connection
  */
 protected function getDbal()
 {
     if (self::$dbal === null) {
         self::$dbal = DriverManager::getConnection(array('pdo' => $this->getPdo()));
     }
     return self::$dbal;
 }
开发者ID:datacompusa,项目名称:vicus-oauth2-server,代码行数:10,代码来源:AbstractDbTestCase.php


示例14: 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


示例15: newConnection

 /**
  * Get an instance of a DBAL Connection
  *
  * @param sting $name the connection name
  * @return Doctrine\DBAL\Connection
  */
 public function newConnection()
 {
     $configuration = new DBAL\Configuration();
     $logger = new MSQLLogger($this);
     $configuration->setSQLLogger($logger);
     return DBAL\DriverManager::getConnection($this->config, $configuration);
 }
开发者ID:joshuacoddingyou,项目名称:php,代码行数:13,代码来源:mdatabase.php


示例16: create

 /**
  * {@inheritdoc}
  */
 public static function create($conn, Configuration $config, EventManager $eventManager = null)
 {
     if (!$config->getMetadataDriverImpl()) {
         throw ORMException::missingMappingDriverImpl();
     }
     switch (true) {
         case is_array($conn):
             if (!$eventManager) {
                 $eventManager = new EventManager();
             }
             if (isset($conn['prefix']) && $conn['prefix']) {
                 $eventManager->addEventListener(Events::loadClassMetadata, new TablePrefix($conn['prefix']));
             }
             $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager);
             break;
         case $conn instanceof Connection:
             if ($eventManager !== null && $conn->getEventManager() !== $eventManager) {
                 throw ORMException::mismatchedEventManager();
             }
             break;
         default:
             throw new \InvalidArgumentException("Invalid argument: " . $conn);
     }
     return new self($conn, $config, $conn->getEventManager());
 }
开发者ID:minchal,项目名称:vero,代码行数:28,代码来源:EntityManager.php


示例17: testDBAL

 public function testDBAL()
 {
     $connectionParams = ['dbname' => $this->conf['dbname'], 'user' => $this->conf['username'], 'password' => $this->conf['password'], 'host' => $this->conf['host'], 'driver' => 'pdo_pgsql'];
     $conn = DriverManager::getConnection($connectionParams);
     $conn->exec(file_get_contents(__DIR__ . '/fixtures/createTable.sql'));
     $sth = $conn->query("SELECT * FROM PUBLIC.TBUPSERTEXAMPLE");
     $result = $sth->fetchAll();
     $this->assertEquals(0, count($result));
     $conn->transactional(function ($conn) {
         Upsert::createFromDBAL($conn)->exec('PUBLIC.TBUPSERTEXAMPLE', ['key1' => 'key1', 'key2' => 'key2', 'key3' => 'key3', 'key4' => 'key4'], ['value1' => 'value1', 'value2' => 'value2', 'value3' => 'value3', 'value4' => null, 'value5' => 'value5']);
     });
     $sth = $conn->query("SELECT * FROM PUBLIC.TBUPSERTEXAMPLE");
     $result = $sth->fetchAll();
     $this->assertEquals('value1', $result[0]['value1']);
     $this->assertEquals('value2', $result[0]['value2']);
     $this->assertEquals('value3', $result[0]['value3']);
     $this->assertEquals(null, $result[0]['value4']);
     $this->assertEquals('value5', $result[0]['value5']);
     $conn->transactional(function ($conn) {
         Upsert::createFromDBAL($conn)->exec('PUBLIC.TBUPSERTEXAMPLE', ['key1' => 'key1', 'key2' => 'key2', 'key3' => 'key3', 'key4' => 'key4'], ['value1' => 'value1', 'value2' => 'value2', 'value3' => 'value3', 'value4' => 'value4', 'value5' => 'value5']);
     });
     $sth = $conn->query("SELECT * FROM PUBLIC.TBUPSERTEXAMPLE");
     $result = $sth->fetchAll();
     $this->assertEquals('value1', $result[0]['value1']);
     $this->assertEquals('value2', $result[0]['value2']);
     $this->assertEquals('value3', $result[0]['value3']);
     $this->assertEquals('value4', $result[0]['value4']);
     $this->assertEquals('value5', $result[0]['value5']);
     $conn->exec(file_get_contents(__DIR__ . '/fixtures/dropTable.sql'));
 }
开发者ID:gonzalo123,项目名称:sqlutils,代码行数:30,代码来源:UpsertTest.php


示例18: setUp

 /**
  * Sets up the tests
  */
 public function setUp()
 {
     $dataPath = realpath(__DIR__ . '/..');
     $this->config = parse_ini_file($dataPath . '/data/entities.doctrine.ini', true);
     $connection = DriverManager::getConnection(['url' => $this->config['databaseUrl']]);
     $this->transactor = new DoctrineTransactor($connection);
     $this->idAccessorRegistry = new IdAccessorRegistry();
     $repositoryFactory = new RepositoryFactory($this->config, $connection, $this->transactor);
     $this->idAccessorRegistry->registerIdAccessors(User::class, function (User $user) {
         return $user->getId();
     }, function (User $user, $id) {
         $user->setId($id);
     });
     $strategy = new RecursiveDirectoryStrategy($this->config['definitionPath']);
     $locator = new Locator([$strategy]);
     $this->builder = new EntityBuilder($locator, $repositoryFactory);
     $this->repo = $repositoryFactory->forEntity(User::class);
     $this->entityRegistry = $repositoryFactory->getEntityRegistry();
     $this->unitOfWork = new UnitOfWorkAccessDecorator($repositoryFactory->getUnitOfWork());
     $this->dataMapper = $this->unitOfWork->getDataMapper(User::class);
     /**
      * The Ids are purposely unique so that we can identify them as such without having to first insert them to
      * assign unique Ids
      * They are also purposely set to 724, 1987, and 345 so that they won't potentially overlap with any default
      * values set to the Ids
      */
     $this->entity1 = new User(724, "foo");
     $this->entity2 = new User(1987, "bar");
     $this->entity3 = new User(345, "baz");
 }
开发者ID:nibra,项目名称:joomla-pythagoras,代码行数:33,代码来源:UnitOfWorkTest.php


示例19: handleDatabaseCreate

 public function handleDatabaseCreate(Args $args, IO $io, Command $command)
 {
     $params = $this->app['doctrine.settings']['dbal'];
     $name = $params['dbname'] ?? null;
     if (false == $name) {
         $io->writeLine("<error>Database's name is missing from provided settings.</error>");
         return 1;
     }
     unset($params['dbname']);
     $tmpConn = DriverManager::getConnection($params);
     if (!$tmpConn->getDriver()->getDatabasePlatform() instanceof MySqlPlatform) {
         $io->writeLine("<warn>This command only support MySQL database, sorry!</warn>");
         return 1;
     }
     $shouldNotCreateDatabase = in_array($name, $tmpConn->getSchemaManager()->listDatabases());
     if ($shouldNotCreateDatabase) {
         $io->writeLine("<warn>Database '{$name}' already exists.</warn>");
         return 1;
     }
     $sql = "CREATE DATABASE `{$name}`";
     if (isset($params['collation']) && isset($params['charset'])) {
         $sql .= ' CHARACTER SET ' . $params['charset'] . ' COLLATE ' . $params['collation'];
     }
     $tmpConn->executeUpdate($sql);
     $tmpConn->close();
     $io->writeLine("<info>Database '{$name}' created.</info>");
     return 0;
 }
开发者ID:eric-chau,项目名称:doctrine-skill,代码行数:28,代码来源:DoctrineCommandHandler.php


示例20: getConnection

 /**
  * @return \Doctrine\DBAL\Connection
  */
 public static function getConnection()
 {
     //setup configuration for connect to the database
     $configuration = array('dbname' => getenv("DB_NAME"), 'user' => getenv("DB_USER"), 'password' => getenv("DB_PASS"), 'host' => getenv("DB_HOST"), 'driver' => getenv("DB_DRIVER"), 'charset' => getenv("DB_CHARSET"));
     //connect to the database using Doctrine\DBAL library
     return DriverManager::getConnection($configuration);
 }
开发者ID:akbarjimi,项目名称:dialog,代码行数:10,代码来源:Connector.php



注:本文中的Doctrine\DBAL\DriverManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Configuration\Configuration类代码示例发布时间:2022-05-23
下一篇:
PHP DBAL\DBALException类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap