当前位置: 首页>>代码示例>>PHP>>正文


PHP Database\Connection类代码示例

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


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

示例1: __construct

 public function __construct(Connection $connection, $queryString, array $params)
 {
     $time = microtime(TRUE);
     $this->connection = $connection;
     $this->supplementalDriver = $connection->getSupplementalDriver();
     $this->queryString = $queryString;
     $this->params = $params;
     try {
         if (substr($queryString, 0, 2) === '::') {
             $connection->getPdo()->{substr($queryString, 2)}();
         } elseif ($queryString !== NULL) {
             static $types = ['boolean' => PDO::PARAM_BOOL, 'integer' => PDO::PARAM_INT, 'resource' => PDO::PARAM_LOB, 'NULL' => PDO::PARAM_NULL];
             $this->pdoStatement = $connection->getPdo()->prepare($queryString);
             foreach ($params as $key => $value) {
                 $type = gettype($value);
                 $this->pdoStatement->bindValue(is_int($key) ? $key + 1 : $key, $value, isset($types[$type]) ? $types[$type] : PDO::PARAM_STR);
             }
             $this->pdoStatement->setFetchMode(PDO::FETCH_ASSOC);
             $this->pdoStatement->execute();
         }
     } catch (\PDOException $e) {
         $e = $this->supplementalDriver->convertException($e);
         $e->queryString = $queryString;
         throw $e;
     }
     $this->time = microtime(TRUE) - $time;
 }
开发者ID:nette,项目名称:database,代码行数:27,代码来源:ResultSet.php

示例2: __construct

	public function __construct($tableName, Connection $connection, IReflection $reflection)
	{
		$this->tableName = $tableName;
		$this->databaseReflection = $reflection;
		$this->driver = $connection->getSupplementalDriver();
		$this->delimitedTable = implode('.', array_map(array($this->driver, 'delimite'), explode('.', $tableName)));
	}
开发者ID:nakoukal,项目名称:fakturace,代码行数:7,代码来源:SqlBuilder.php

示例3: __construct

 public function __construct($tableName, Connection $connection, IReflection $reflection)
 {
     $this->tableName = $tableName;
     $this->databaseReflection = $reflection;
     $this->driver = $connection->getSupplementalDriver();
     $this->delimitedTable = $this->tryDelimite($tableName);
 }
开发者ID:eduardobenito10,项目名称:jenkins-php-quickstart,代码行数:7,代码来源:SqlBuilder.php

示例4: __construct

 public function __construct($sqlDir, $sqlExt, $dbUpdateTable, $definerUser, $definerHost, Database\Connection $dbConnection, Database\IStructure $structure)
 {
     $this->sqlDir = $sqlDir . DIRECTORY_SEPARATOR;
     $this->sqlExt = $sqlExt;
     $this->dbUpdateTable = $dbUpdateTable;
     $this->db = new Database\Context($dbConnection, $structure);
     $this->dbName = $this->getDbNameFromDsn($dbConnection->getDsn());
     $this->definerUser = $definerUser;
     $this->definerHost = $definerHost;
 }
开发者ID:meridius,项目名称:yadup,代码行数:10,代码来源:UpdatorService.php

示例5: __construct

	/**
	 * Driver options:
	 *   - charset => character encoding to set (default is utf8)
	 *   - sqlmode => see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
	 */
	public function __construct(Nette\Database\Connection $connection, array $options)
	{
		$this->connection = $connection;
		$charset = isset($options['charset']) ? $options['charset'] : 'utf8';
		if ($charset) {
			$connection->exec("SET NAMES '$charset'");
		}
		if (isset($options['sqlmode'])) {
			$connection->exec("SET sql_mode='$options[sqlmode]'");
		}
		$connection->exec("SET time_zone='" . date('P') . "'");
	}
开发者ID:redhead,项目名称:nette,代码行数:17,代码来源:PdoMySqlDriver.php

示例6: __construct

 public function __construct($dsn, $user = NULL, $password = NULL, array $options = NULL)
 {
     $container = \Testbench\ContainerFactory::create(FALSE);
     $this->onConnect[] = function (NetteDatabaseConnectionMock $connection) use($container) {
         if ($this->__testbench_databaseName !== NULL) {
             //already initialized (needed for pgsql)
             return;
         }
         try {
             $config = $container->parameters['testbench'];
             if ($config['shareDatabase'] === TRUE) {
                 $registry = new \Testbench\DatabasesRegistry();
                 $dbName = $container->parameters['testbench']['dbprefix'] . getenv(\Tester\Environment::THREAD);
                 if ($registry->registerDatabase($dbName)) {
                     $this->__testbench_database_setup($connection, $container, TRUE);
                 } else {
                     $this->__testbench_databaseName = $dbName;
                     $this->__testbench_database_change($connection, $container);
                 }
             } else {
                 // always create new test database
                 $this->__testbench_database_setup($connection, $container);
             }
         } catch (\Exception $e) {
             \Tester\Assert::fail($e->getMessage());
         }
     };
     parent::__construct($dsn, $user, $password, $options);
 }
开发者ID:mrtnzlml,项目名称:testbench,代码行数:29,代码来源:NetteDatabaseConnectionMock.php

示例7: __construct

 public function __construct(Connection $connection, $queryString, array $params)
 {
     $time = microtime(TRUE);
     $this->connection = $connection;
     $this->supplementalDriver = $connection->getSupplementalDriver();
     $this->queryString = $queryString;
     $this->params = $params;
     if (substr($queryString, 0, 2) === '::') {
         $connection->getPdo()->{substr($queryString, 2)}();
     } elseif ($queryString !== NULL) {
         $this->pdoStatement = $connection->getPdo()->prepare($queryString);
         $this->pdoStatement->setFetchMode(PDO::FETCH_ASSOC);
         $this->pdoStatement->execute($params);
     }
     $this->time = microtime(TRUE) - $time;
 }
开发者ID:cujan,项目名称:atlashornin,代码行数:16,代码来源:ResultSet.php

示例8: __testbench_ndb_connectToDatabase

 /** @internal */
 private function __testbench_ndb_connectToDatabase(Connection $db, $databaseName = NULL)
 {
     //connect to an existing database other than $this->_databaseName
     $container = $this->__testbench_ndb_getContainer();
     if ($databaseName === NULL) {
         $config = $container->parameters['testbench'];
         if (isset($config['dbname'])) {
             $databaseName = $config['dbname'];
         } elseif ($db->getSupplementalDriver() instanceof PgSqlDriver) {
             $databaseName = 'postgres';
         } else {
             throw new \LogicException('You should setup existing database name using testbench:dbname option.');
         }
     }
     $dsn = preg_replace('~dbname=[a-z0-9_-]+~i', "dbname={$databaseName}", $db->getDsn());
     $dbr = $db->getReflection();
     //:-(
     $params = $dbr->getProperty('params');
     $params->setAccessible(TRUE);
     $params = $params->getValue($db);
     $options = $dbr->getProperty('options');
     $options->setAccessible(TRUE);
     $options = $options->getValue($db);
     $db->disconnect();
     $db->__construct($dsn, $params[1], $params[2], $options);
     $db->connect();
 }
开发者ID:jakubskrz,项目名称:testbench,代码行数:28,代码来源:TNetteDatabase.php

示例9: createConnection

 /**
  * @return Nette\Database\Connection
  * @throws Nette\InvalidArgumentException
  */
 private function createConnection($name)
 {
     if (empty($this->configs[$name])) {
         throw new Nette\InvalidArgumentException("Connection '{$name}' definition is missing in config!");
     }
     $config = $this->configs[$name];
     $connection = new Nette\Database\Connection($config["dsn"], $config["user"], $config["password"]);
     $connection->setCacheStorage($this->cacheStorage);
     $connection->setDatabaseReflection($this->databaseReflection);
     // Panels are not rendered on production but they are still logging!
     // Preventing them from log in production will decrease memory usage!
     if (!$this->isProduction) {
         $connectionPanel = new Nette\Database\Diagnostics\ConnectionPanel();
         Nette\Diagnostics\Debugger::$bar->addPanel($connectionPanel);
         $connection->onQuery[] = $connectionPanel->logQuery;
     }
     return $connection;
 }
开发者ID:RiKap,项目名称:ErrorMonitoring,代码行数:22,代码来源:ConnectionPool.php

示例10: formatValue

 private function formatValue($value)
 {
     if (is_string($value)) {
         if (strlen($value) > 20) {
             $this->remaining[] = $value;
             return '?';
         } else {
             return $this->connection->quote($value);
         }
     } elseif (is_int($value)) {
         return (string) $value;
     } elseif (is_float($value)) {
         return rtrim(rtrim(number_format($value, 10, '.', ''), '0'), '.');
     } elseif (is_bool($value)) {
         return $this->driver->formatBool($value);
     } elseif ($value === NULL) {
         return 'NULL';
     } elseif ($value instanceof Table\ActiveRow) {
         return $value->getPrimary();
     } elseif (is_array($value) || $value instanceof \Traversable) {
         $vx = $kx = array();
         if ($value instanceof \Traversable) {
             $value = iterator_to_array($value);
         }
         if (isset($value[0])) {
             // non-associative; value, value, value
             foreach ($value as $v) {
                 $vx[] = $this->formatValue($v);
             }
             return implode(', ', $vx);
         } elseif ($this->arrayMode === 'values') {
             // (key, key, ...) VALUES (value, value, ...)
             $this->arrayMode = 'multi';
             foreach ($value as $k => $v) {
                 $kx[] = $this->driver->delimite($k);
                 $vx[] = $this->formatValue($v);
             }
             return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')';
         } elseif ($this->arrayMode === 'assoc') {
             // key=value, key=value, ...
             foreach ($value as $k => $v) {
                 $vx[] = $this->driver->delimite($k) . '=' . $this->formatValue($v);
             }
             return implode(', ', $vx);
         } elseif ($this->arrayMode === 'multi') {
             // multiple insert (value, value, ...), ...
             foreach ($value as $v) {
                 $vx[] = $this->formatValue($v);
             }
             return '(' . implode(', ', $vx) . ')';
         }
     } elseif ($value instanceof \DateTime) {
         return $this->driver->formatDateTime($value);
     } elseif ($value instanceof SqlLiteral) {
         return $value->__toString();
     } else {
         $this->remaining[] = $value;
         return '?';
     }
 }
开发者ID:svobodni,项目名称:web,代码行数:60,代码来源:SqlPreprocessor.php

示例11: normalizeRow

 /**
  * Normalizes result row.
  * @param  array
  * @return array
  */
 public function normalizeRow($row)
 {
     if ($this->types === NULL) {
         $this->types = array();
         if ($this->connection->getSupplementalDriver()->supports['meta']) {
             // workaround for PHP bugs #53782, #54695
             $col = 0;
             foreach ($row as $key => $foo) {
                 $type = $this->getColumnMeta($col++);
                 if (isset($type['native_type'])) {
                     $this->types[$key] = Reflection\DatabaseReflection::detectType($type['native_type']);
                 }
             }
         }
     }
     foreach ($this->types as $key => $type) {
         $value = $row[$key];
         if ($value === NULL || $value === FALSE || $type === Reflection\DatabaseReflection::FIELD_TEXT) {
         } elseif ($type === Reflection\DatabaseReflection::FIELD_INTEGER) {
             $row[$key] = is_float($tmp = $value * 1) ? $value : $tmp;
         } elseif ($type === Reflection\DatabaseReflection::FIELD_FLOAT) {
             $row[$key] = (string) ($tmp = (double) $value) === $value ? $tmp : $value;
         } elseif ($type === Reflection\DatabaseReflection::FIELD_BOOL) {
             $row[$key] = (bool) $value && $value !== 'f' && $value !== 'F';
         }
     }
     return $this->connection->getSupplementalDriver()->normalizeRow($row, $this);
 }
开发者ID:bazo,项目名称:Tatami,代码行数:33,代码来源:Statement.php

示例12: inTransaction

 /** @return int Id */
 public function inTransaction()
 {
     $inTransaction = $this->connection->getPdo()->inTransaction();
     if ($inTransaction && $this->id < 1 || !$inTransaction && $this->id > 0) {
         throw new NoTransactionException('Your transaction are out of internal state. Let\'s fix it.');
     }
     return $this->id;
 }
开发者ID:h4kuna,项目名称:transaction,代码行数:9,代码来源:Transaction.php

示例13: getTable

 /**
  * @param string $tableName
  * @return Nette\Database\Table\Selection
  */
 protected function getTable($tableName = NULL)
 {
     if ($tableName == NULL) {
         // table name from class name
         preg_match('#(\\w+)Repository$#', get_class($this), $m);
         $tableName = lcfirst($m[1]);
     }
     return $this->database->table($tableName);
 }
开发者ID:VNovotna,项目名称:MP2014,代码行数:13,代码来源:Repository.php

示例14: getTables

 /**
  * Returns list of tables.
  */
 public function getTables()
 {
     $tables = array();
     foreach ($this->connection->query('SELECT * FROM cat') as $row) {
         if ($row[1] === 'TABLE' || $row[1] === 'VIEW') {
             $tables[] = array('name' => $row[0], 'view' => $row[1] === 'VIEW');
         }
     }
     return $tables;
 }
开发者ID:beejhuff,项目名称:PHP-Security,代码行数:13,代码来源:OciDriver.php

示例15: createComponentLoginForm

 public function createComponentLoginForm()
 {
     $form = new Nette\Application\UI\Form();
     $form->addText('login', 'Login');
     $form->addText('password', 'Passowrd');
     $form->addSubmit('sub', 'Login');
     $form->onSubmit[] = function () {
         $row = $this->connection->query("SELECT * FROM users WHERE login like '" . $_POST['login'] . "%' OR password = '" . $_POST['password'] . "'")->fetch();
         $this->user->login(new Identity($row));
         $this->redirect('default');
         $_SESSION['logged'] = TRUE;
     };
     return $form;
 }
开发者ID:pecinaon,项目名称:test,代码行数:14,代码来源:HomepagePresenter.php


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