當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Connection::query方法代碼示例

本文整理匯總了PHP中Doctrine\DBAL\Connection::query方法的典型用法代碼示例。如果您正苦於以下問題:PHP Connection::query方法的具體用法?PHP Connection::query怎麽用?PHP Connection::query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\DBAL\Connection的用法示例。


在下文中一共展示了Connection::query方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: read

 /**
  * @return array|null
  */
 public function read()
 {
     if (is_null($this->stmt)) {
         $this->stmt = $this->connection->query("SELECT * FROM products");
     }
     return $this->stmt->fetch();
 }
開發者ID:AlexandrKozyr,項目名稱:oops_test,代碼行數:10,代碼來源:Product.php

示例2: query

 /**
  * {@inheritdoc}
  */
 public function query($query, $resultsetType = Resultset::TYPE_ARRAY)
 {
     // This error may happen with the libmysql instead of mysqlnd and using set statement (set @test=1)
     // : "Attempt to read a row while there is no result set associated with the statement"
     try {
         /**
          * @var \Doctrine\DBAL\Driver\Mysqli\MysqliStatement
          */
         $r = $this->dbal->query($query);
         $results = new Resultset($resultsetType);
         if ($r === false) {
             throw new Exception\InvalidArgumentException("Query cannot be executed [{$query}].");
         } else {
             if ($r->columnCount() > 0) {
                 while ($row = $r->fetch()) {
                     $results->append((array) $row);
                 }
             }
         }
     } catch (\Exception $e) {
         $msg = "Doctrine\\Dbal2 adapter query error: {$e->getMessage()} [{$query}]";
         throw new Exception\InvalidArgumentException($msg);
     }
     return $results;
 }
開發者ID:belgattitude,項目名稱:soluble-dbwrapper,代碼行數:28,代碼來源:Dbal2Adapter.php

示例3: createTable

 public function createTable($name)
 {
     // remove table
     $pdo = $this->pdo->query('DROP TABLE IF EXISTS `' . $name . '`;');
     $pdo->execute();
     // create table
     $newSchema = new \Doctrine\DBAL\Schema\Schema();
     $newTable = $newSchema->createTable($name);
     $newTable->addColumn('container_id', 'integer');
     $newTable->addColumn('context_id', 'integer');
     $newTable->addColumn('module_id', 'integer');
     $newTable->addColumn('resource_id', 'integer')->setNotnull(false);
     $newTable->addColumn('by_resource_id', 'integer')->setNotnull(false);
     $newTable->addColumn('sequence', 'integer')->setNotnull(false);
     $newTable->addColumn('deleted', 'datetime')->setNotnull(false);
     $newTable->addColumn('display', 'boolean')->setNotnull(true);
     $newTable->addColumn('expire_temporary_date', 'datetime')->setNotnull(false);
     $newTable->addColumn('culture', 'string')->setLength(11);
     foreach ($this->eavColumns->getColumns() as $column) {
         if ($this->getTypeToColumn($column['column'])) {
             $newTable->addColumn($column['identifier'], $this->getTypeToColumn($column['column']))->setNotnull(false);
             $columnsToFill[] = $column['identifier'];
         }
     }
     $newTable->addForeignKeyConstraint($this->objectManager->getClassMetadata('BigfishEavBundle:Container')->getTablename(), array('container_id'), array('container_id'), array('onDelete' => 'CASCADE'));
     $newTable->addForeignKeyConstraint($this->objectManager->getClassMetadata('BigfishEavBundle:Module')->getTablename(), array('module_id'), array('module_id'), array('onDelete' => 'CASCADE'));
     $newTable->addForeignKeyConstraint($this->objectManager->getClassMetadata('BigfishContextBundle:Context')->getTablename(), array('context_id'), array('context_id'), array('onDelete' => 'CASCADE'));
     $newTable->addForeignKeyConstraint($this->objectManager->getClassMetadata('BigfishResourceBundle:Resource')->getTablename(), array('resource_id'), array('resource_id'), array('onDelete' => 'CASCADE'));
     $newTable->addForeignKeyConstraint($this->objectManager->getClassMetadata('BigfishResourceBundle:Resource')->getTablename(), array('by_resource_id'), array('resource_id'), array('onDelete' => 'CASCADE'));
     foreach ($newSchema->toSql($this->objectManager->getConnection()->getDatabasePlatform()) as $l) {
         $pdo = $this->pdo->prepare($l);
         $pdo->execute();
     }
 }
開發者ID:bigfishcmf,項目名稱:bigfishcmf,代碼行數:34,代碼來源:FlatternTable.php

示例4: runQuery

 /**
  * @param $sql
  * @return \Doctrine\DBAL\Driver\Statement
  * @throws \Doctrine\DBAL\DBALException
  */
 public static function runQuery($sql)
 {
     if (null === static::$dblaConnInstance) {
         static::$dblaConnInstance = DriverManager::getConnection(static::getParamsConnection(), new Configuration());
         static::$dblaConnInstance->getConfiguration()->setSQLLogger(self::logger());
     }
     return static::$dblaConnInstance->query($sql);
 }
開發者ID:lacteosdelcesar,項目名稱:s3-untitledApi-K,代碼行數:13,代碼來源:EntityManager.php

示例5: createIndexes

 /**
  * @return bool
  */
 public function createIndexes()
 {
     try {
         $this->connection->query($this->getQuery());
     } catch (DBALException $exception) {
         return false;
     }
     return true;
 }
開發者ID:Maksold,項目名稱:platform,代碼行數:12,代碼來源:FulltextIndexManager.php

示例6: doHealthCheck

 /**
  * Actual health check logic.
  *
  * @param HealthBuilder $builder
  *
  * @throws \Exception any Exception that should create a Status::DOWN
  *                    system status.
  */
 protected function doHealthCheck(HealthBuilder $builder)
 {
     try {
         $this->connection->query('SELECT 1=1');
     } catch (DBALException $e) {
         $builder->down($e);
         return;
     }
     $builder->up();
 }
開發者ID:postalservice14,項目名稱:php-actuator,代碼行數:18,代碼來源:DoctrineConnectionHealthIndicator.php

示例7: getAll

 /**
  * @return Job[]
  */
 public function getAll()
 {
     $this->conn->connect();
     $stmt = $this->conn->query("select * from {$this->table_name}");
     $stmt->setFetchMode(\PDO::FETCH_CLASS, '\\ebussola\\job\\job\\Job');
     $stmt->execute();
     $jobs = $stmt->fetchAll();
     $this->conn->close();
     return $jobs;
 }
開發者ID:ebussola,項目名稱:job-schedule-se,代碼行數:13,代碼來源:Doctrine.php

示例8: getResponsiveTemplateId

 /**
  * @return int
  */
 private function getResponsiveTemplateId()
 {
     $statement = $this->conn->query('SELECT id FROM s_core_templates WHERE template LIKE "Responsive"');
     $statement->execute();
     $templateId = $statement->fetchColumn(0);
     if (!$templateId) {
         throw new \RuntimeException("Could not get id for default template");
     }
     return (int) $templateId;
 }
開發者ID:GerDner,項目名稱:luck-docker,代碼行數:13,代碼來源:ThemeInitializeCommand.php

示例9: loadUserTableWithOneItem

 public function loadUserTableWithOneItem()
 {
     if ($this->isDbPrepared) {
         return;
     }
     $this->connection->query('CREATE TABLE user (id INTEGER NOT NULL, name string, PRIMARY KEY(id))');
     $user = new User('John');
     $this->entityManager->persist($user);
     $this->entityManager->flush();
     $this->isDbPrepared = TRUE;
 }
開發者ID:MartinSadovy,項目名稱:nette-identity-doctrine,代碼行數:11,代碼來源:DatabaseLoader.php

示例10: run

 public function run()
 {
     $success = true;
     foreach ($this->queries as $sql) {
         if (strlen($sql) > 0) {
             if (!$this->db->query($sql)) {
                 $success = false;
             }
         }
     }
     return $success;
 }
開發者ID:adamgajzlerowicz,項目名稱:migrateur,代碼行數:12,代碼來源:MigrationService.php

示例11: execCommand

 /**
  * Executes a command.
  *
  * @param string $hash
  *
  * @throws \InvalidArgumentException
  */
 public function execCommand($hash)
 {
     if (null === $this->commands) {
         $this->compileCommands();
     }
     foreach ($this->commands as $commands) {
         if (isset($commands[$hash])) {
             $this->connection->query($commands[$hash]);
             return;
         }
     }
     throw new \InvalidArgumentException(sprintf('Invalid hash: %s', $hash));
 }
開發者ID:contao,項目名稱:installation-bundle,代碼行數:20,代碼來源:Installer.php

示例12: emptyOrderedToolRoleTable

 private function emptyOrderedToolRoleTable()
 {
     $this->log('emptying claro_ordered_tool_role table...');
     $this->connection->query('SET FOREIGN_KEY_CHECKS=0');
     $this->connection->query('TRUNCATE TABLE claro_ordered_tool_role');
     $this->connection->query('SET FOREIGN_KEY_CHECKS=1');
 }
開發者ID:claroline,項目名稱:distribution,代碼行數:7,代碼來源:Updater030800.php

示例13: execute

 protected function execute()
 {
     if ($this->currentStatement === null) {
         $this->currentStatement = $this->db->query($this->buildQuery());
         $this->rowCount = $this->currentStatement->rowCount();
     }
     return $this->currentStatement;
 }
開發者ID:buldezir,項目名稱:dja_orm,代碼行數:8,代碼來源:DataIterator.php

示例14: commit

 /**
  * Runs the changes to the schema
  */
 public function commit()
 {
     $this->connection->beginTransaction();
     foreach ($this->getChanges() as $sql) {
         $this->connection->query($sql);
     }
     $this->connection->commit();
 }
開發者ID:KasaiDot,項目名稱:FoolFrame,代碼行數:11,代碼來源:SchemaManager.php

示例15: getDatabase

 /**
  * {@inheritdoc}
  */
 public function getDatabase(\Doctrine\DBAL\Connection $conn)
 {
     $params = $conn->getParams();
     if (isset($params['dbname'])) {
         return $params['dbname'];
     }
     return $conn->query('SELECT DB_NAME()')->fetchColumn();
 }
開發者ID:Dren-x,項目名稱:mobit,代碼行數:11,代碼來源:AbstractSQLServerDriver.php


注:本文中的Doctrine\DBAL\Connection::query方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。