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

PHP Database\Connection类代码示例

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

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



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

    public function getPanel()
    {
        $s = '';
        $h = 'htmlSpecialChars';
        foreach ($this->queries as $i => $query) {
            list($sql, $params, $time, $rows, $connection, $source) = $query;
            $explain = NULL;
            // EXPLAIN is called here to work SELECT FOUND_ROWS()
            if ($this->explain && preg_match('#\\s*SELECT\\s#iA', $sql)) {
                try {
                    $explain = $connection->queryArgs('EXPLAIN ' . $sql, $params)->fetchAll();
                } catch (\PDOException $e) {
                }
            }
            $s .= '<tr><td>' . sprintf('%0.3f', $time * 1000);
            if ($explain) {
                $s .= "<br /><a href='#' class='nette-toggler' rel='#nette-debug-database-row-{$h($this->name)}-{$i}'>explain&nbsp;&#x25ba;</a>";
            }
            $s .= '</td><td class="database-sql">' . Connection::highlightSql(Nette\String::truncate($sql, self::$maxLength));
            if ($explain) {
                $s .= "<table id='nette-debug-database-row-{$h($this->name)}-{$i}' class='nette-collapsed'><tr>";
                foreach ($explain[0] as $col => $foo) {
                    $s .= "<th>{$h($col)}</th>";
                }
                $s .= "</tr>";
                foreach ($explain as $row) {
                    $s .= "<tr>";
                    foreach ($row as $col) {
                        $s .= "<td>{$h($col)}</td>";
                    }
                    $s .= "</tr>";
                }
                $s .= "</table>";
            }
            if ($source) {
                list($file, $line) = $source;
                $s .= (Nette\Debug::$editor ? "<a href='{$h(Nette\DebugHelpers::editorLink($file, $line))}'" : '<span') . " class='database-source' title='{$h($file)}:{$line}'>" . "{$h(basename(dirname($file)) . '/' . basename($file))}:{$line}" . (Nette\Debug::$editor ? '</a>' : '</span>');
            }
            $s .= '</td><td>';
            foreach ($params as $param) {
                $s .= "{$h(Nette\String::truncate($param, self::$maxLength))}<br>";
            }
            $s .= '</td><td>' . $rows . '</td></tr>';
        }
        return empty($this->queries) ? '' : '<style> #nette-debug-database td.database-sql { background: white !important }
			#nette-debug-database .database-source { color: #BBB !important }
			#nette-debug-database tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style>
			<h1>Queries: ' . count($this->queries) . ($this->totalTime ? ', time: ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : '') . '</h1>
			<div class="nette-inner">
			<table>
				<tr><th>Time&nbsp;ms</th><th>SQL Statement</th><th>Params</th><th>Rows</th></tr>' . $s . '
			</table>
			</div>';
    }
开发者ID:JanTvrdik,项目名称:nette,代码行数:54,代码来源:DatabasePanel.php


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


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


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


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


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


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


示例17: initDatabase

 private function initDatabase($fileName = null)
 {
     $reflection = \Nette\Reflection\ClassType::from(get_class($this));
     $dir = dirname($reflection->getFileName());
     $fileName = $fileName ? $fileName : $dir . '/init.sql';
     $initSql = file_get_contents($fileName);
     $queries = explode(';', $initSql);
     foreach ($queries as $query) {
         if (empty($query)) {
             continue;
         }
         $this->database->query(trim($query));
     }
 }
开发者ID:RiKap,项目名称:ErrorMonitoring,代码行数:14,代码来源:BaseIntegrationTestCase.php


示例18: getForeignKeys

 /**
  * Returns metadata for all foreign keys in a table.
  */
 public function getForeignKeys($table)
 {
     $keys = [];
     $query = 'SELECT \'CONSTRAINT_NAME\', C.COLUMN_NAME, C2.TABLE_NAME AS `REFERENCED_TABLE_NAME`, C2.COLUMN_NAME AS `REFERENCED_COLUMN_NAME` ' . 'FROM information_schema.COLUMNS C ' . 'JOIN information_schema.TABLES T ON T.TABLE_SCHEMA = C.TABLE_SCHEMA ' . 'JOIN information_schema.COLUMNS C2 ON C2.TABLE_SCHEMA = C.TABLE_SCHEMA ' . 'WHERE 1 ' . 'AND C.TABLE_SCHEMA = DATABASE() ' . 'AND C.TABLE_NAME = ' . $this->connection->quote($table) . ' ' . 'AND C.COLUMN_KEY != \'\' ' . 'AND C2.TABLE_NAME = T.TABLE_NAME ' . 'AND ( ' . '( ' . 'C.COLUMN_COMMENT REGEXP \'^\\s*@refs [a-zA-Z_]+\\.[a-zA-Z_]+\' ' . 'AND C.COLUMN_COMMENT LIKE CONCAT(\'@refs \', C2.TABLE_NAME, \'\\.\', C2.COLUMN_NAME, \'%\') ' . ') ' . 'OR ( ' . 'C.COLUMN_NAME LIKE CONCAT(T.TABLE_NAME, \'\\_%\') ' . 'AND REPLACE(C.COLUMN_NAME, CONCAT(T.TABLE_NAME, \'_\'), \'\') = C2.COLUMN_NAME' . ') ' . ')';
     foreach ($this->connection->query($query) as $id => $row) {
         $keys[$id]['name'] = 'FK_' . $table . '_' . $row['REFERENCED_TABLE_NAME'] . '_' . $row['REFERENCED_COLUMN_NAME'];
         // foreign key name
         $keys[$id]['local'] = $row['COLUMN_NAME'];
         // local columns
         $keys[$id]['table'] = $row['REFERENCED_TABLE_NAME'];
         // referenced table
         $keys[$id]['foreign'] = $row['REFERENCED_COLUMN_NAME'];
         // referenced columns
     }
     return array_values($keys);
 }
开发者ID:sysel,项目名称:nette-database-myisam,代码行数:19,代码来源:MySqlMyIsamDriver.php


示例19: normalizeRow

	/**
	 * Normalizes result row.
	 * @param  array
	 * @return array
	 */
	public function normalizeRow($row)
	{
		if ($this->types === NULL) {
			try {
				$this->types = array();
				foreach ($row as $key => $foo) {
					$type = $this->getColumnMeta(count($this->types));
					if (isset($type['native_type'])) {
						$this->types[$key] = DatabaseReflection::detectType($type['native_type']);
					}
				}
			} catch (\PDOException $e) {
			}
		}
		foreach ($this->types as $key => $type) {
			$value = $row[$key];
			if ($value === NULL || $value === FALSE || $type === DatabaseReflection::FIELD_TEXT) {

			} elseif ($type === DatabaseReflection::FIELD_INTEGER) {
				$row[$key] = is_float($tmp = $value * 1) ? $value : $tmp;

			} elseif ($type === DatabaseReflection::FIELD_FLOAT) {
				$row[$key] = (string) ($tmp = (float) $value) === $value ? $tmp : $value;

			} elseif ($type === DatabaseReflection::FIELD_BOOL) {
				$row[$key] = ((bool) $value) && $value !== 'f' && $value !== 'F';
			}
		}

		return $this->connection->getSupplementalDriver()->normalizeRow($row, $this);
	}
开发者ID:JanTvrdik,项目名称:StaticWeb,代码行数:36,代码来源:Statement.php


示例20: tryDelimite

 protected function tryDelimite($s)
 {
     $driver = $this->connection->getSupplementalDriver();
     return preg_replace_callback('#(?<=[^\\w`"\\[]|^)[a-z_][a-z0-9_]*(?=[^\\w`"(\\]]|$)#i', function ($m) use($driver) {
         return strtoupper($m[0]) === $m[0] ? $m[0] : $driver->delimite($m[0]);
     }, $s);
 }
开发者ID:cujan,项目名称:atlas-mineralov-a-hornin,代码行数:7,代码来源:SqlBuilder.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP Database\Context类代码示例发布时间:2022-05-23
下一篇:
PHP Caching\Cache类代码示例发布时间: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