本文整理汇总了PHP中Nette\Database\Connection::getPdo方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::getPdo方法的具体用法?PHP Connection::getPdo怎么用?PHP Connection::getPdo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Database\Connection
的用法示例。
在下文中一共展示了Connection::getPdo方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: 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;
}
示例3: __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;
}
示例4: __construct
/**
* Driver options:
* - charset => character encoding to set (default is utf8 or utf8mb4 since MySQL 5.5.3)
* - 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'] : (version_compare($connection->getPdo()->getAttribute(\PDO::ATTR_SERVER_VERSION), '5.5.3', '>=') ? 'utf8mb4' : 'utf8');
if ($charset) {
$connection->query("SET NAMES '{$charset}'");
}
if (isset($options['sqlmode'])) {
$connection->query("SET sql_mode='{$options['sqlmode']}'");
}
}
示例5: rollback
/**
* Rollback to savepoint.
*
* @return void
* @throws InvalidTransactionException
*/
public function rollback()
{
if (self::$level === 0) {
throw new InvalidTransactionException('No transaction started');
}
self::$level--;
if (self::$level === 0 || !$this->isSupported()) {
$this->connection->rollBack();
} else {
$this->connection->getPdo()->exec('ROLLBACK TO SAVEPOINT LEVEL' . self::$level);
}
}
示例6: loadFromFile
/**
* Import SQL dump from file - extremely fast.
* @return int count of commands
*/
public static function loadFromFile(Connection $connection, $file)
{
@set_time_limit(0);
// @ function may be disabled
$handle = @fopen($file, 'r');
// @ is escalated to exception
if (!$handle) {
throw new Nette\FileNotFoundException("Cannot open file '{$file}'.");
}
$count = 0;
$delimiter = ';';
$sql = '';
$pdo = $connection->getPdo();
// native query without logging
while (!feof($handle)) {
$s = rtrim(fgets($handle));
if (!strncasecmp($s, 'DELIMITER ', 10)) {
$delimiter = substr($s, 10);
} elseif (substr($s, -strlen($delimiter)) === $delimiter) {
$sql .= substr($s, 0, -strlen($delimiter));
$pdo->exec($sql);
$sql = '';
$count++;
} else {
$sql .= $s . "\n";
}
}
if (trim($sql) !== '') {
$pdo->exec($sql);
$count++;
}
fclose($handle);
return $count;
}
示例7: __construct
public function __construct(Nette\Database\Connection $connection, array $options)
{
$this->connection = $connection;
$this->version = $connection->getPdo()->getAttribute(\PDO::ATTR_SERVER_VERSION);
}