本文整理汇总了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();
}
示例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;
}
示例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();
}
}
示例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);
}
示例5: createIndexes
/**
* @return bool
*/
public function createIndexes()
{
try {
$this->connection->query($this->getQuery());
} catch (DBALException $exception) {
return false;
}
return true;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例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');
}
示例13: execute
protected function execute()
{
if ($this->currentStatement === null) {
$this->currentStatement = $this->db->query($this->buildQuery());
$this->rowCount = $this->currentStatement->rowCount();
}
return $this->currentStatement;
}
示例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();
}
示例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();
}