本文整理汇总了PHP中PDO::rollback方法的典型用法代码示例。如果您正苦于以下问题:PHP PDO::rollback方法的具体用法?PHP PDO::rollback怎么用?PHP PDO::rollback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PDO
的用法示例。
在下文中一共展示了PDO::rollback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transaction
/**
* @param \Closure $queries
* @return bool
*/
public function transaction(\Closure $queries)
{
$this->connection->beginTransaction();
try {
$queries($this);
$this->connection->commit();
return true;
} catch (Exception $e) {
$this->connection->rollback();
return false;
}
}
示例2: transactional
/**
* Executes a function in a transaction.
*
* @param callable $callable The function to execute transactionally
*
* @return mixed The non-empty value returned from the closure or true instead.
*
* @throws \Exception during execution of the function or transaction commit,
* the transaction is rolled back and the exception re-thrown
*/
public function transactional(callable $callable)
{
$this->pdo->beginTransaction();
try {
$return = call_user_func($callable, $this);
$this->pdo->commit();
return $return ?: true;
} catch (\Exception $exception) {
$this->pdo->rollback();
throw $exception;
}
}
示例3: rollback
/**
* Rollback a transaction.
*/
private function rollback()
{
if ($this->transaction) {
$this->db->rollback();
$this->transaction = false;
}
}
示例4: rollBackTransaction
/**
* Rolls back a transaction and returns true if the rollback was successfull.
*
* @return boolean
*/
public function rollBackTransaction()
{
if ($this->activeTransactions === 0) {
return false;
}
try {
$this->activeTransactions--;
if ($this->activeTransactions === 0) {
if (WCF::benchmarkIsEnabled()) {
Benchmark::getInstance()->start("ROLLBACK", Benchmark::TYPE_SQL_QUERY);
}
$result = $this->pdo->rollback();
} else {
if (WCF::benchmarkIsEnabled()) {
Benchmark::getInstance()->start("ROLLBACK TO SAVEPOINT level" . $this->activeTransactions, Benchmark::TYPE_SQL_QUERY);
}
$result = $this->pdo->exec("ROLLBACK TO SAVEPOINT level" . $this->activeTransactions) !== false;
}
if (WCF::benchmarkIsEnabled()) {
Benchmark::getInstance()->stop();
}
return $result;
} catch (\PDOException $e) {
throw new DatabaseException("Cannot rollback transaction: " . $e->getMessage(), $this);
}
}
示例5: createService
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('config');
try {
$pdo = $pdo = new \PDO($config['dbAdapterPostgre']['dsn'], $config['dbAdapterPostgre']['username'], $config['dbAdapterPostgre']['password']);
$sql = " \n SELECT a.id as id\n FROM info_users a \n where \n a.username = :username ";
$statement = $pdo->prepare($sql);
//print_r('--user id-->'.$serviceLocator->get('identity'));
$statement->bindValue(':username', $serviceLocator->get('identity'), \PDO::PARAM_STR);
//echo debugPDO($sql, $parameters);
$statement->execute();
$result = $statement->fetchAll(\PDO::FETCH_ASSOC);
$userID = true;
if (isset($result[0]['id'])) {
$userID = (int) $result[0]['id'];
}
$errorInfo = $statement->errorInfo();
if ($errorInfo[0] != "00000" && $errorInfo[1] != NULL && $errorInfo[2] != NULL) {
throw new \PDOException($errorInfo[0]);
}
//return array("found" => true, "errorInfo" => $errorInfo, "resultSet" => $result);
return $userID;
} catch (\PDOException $e) {
$pdo->rollback();
return array("found" => false, "errorInfo" => $e->getMessage());
}
}
示例6: rollbackTransaction
/**
* Rollsback a transaction
*
* @return bool true on success, false otherwise
*/
public function rollbackTransaction()
{
if (!$this->_connection->inTransaction()) {
return false;
}
return $this->_connection->rollback();
}
示例7: createService
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('config');
try {
$pdo = $pdo = new \PDO($config['dbAdapterPostgre']['dsn'], $config['dbAdapterPostgre']['username'], $config['dbAdapterPostgre']['password']);
$sql = " \n SELECT \n REPLACE(TRIM(SUBSTRING(crypt(sf_private_key_value,gen_salt('xdes')),6,20)),'/','*') AS public_key\n FROM info_users a \n INNER JOIN sys_acl_roles sar ON sar.id = a.role_id AND sar.active=0 AND sar.deleted=0 \n WHERE a.username = :username \n AND a.password = :password \n AND a.deleted = 0 \n AND a.active = 0 \n Limit 1 \n \n ";
$statement = $pdo->prepare($sql);
$statement->bindValue(':username', $_POST['eposta'], \PDO::PARAM_STR);
$statement->bindValue(':password', md5($_POST['sifre']), \PDO::PARAM_STR);
//echo debugPDO($sql, $parameters);
$statement->execute();
$result = $statement->fetchAll(\PDO::FETCH_ASSOC);
$publicKey = true;
if (isset($result[0]['public_key'])) {
$publicKey = $result[0]['public_key'];
}
$errorInfo = $statement->errorInfo();
if ($errorInfo[0] != "00000" && $errorInfo[1] != NULL && $errorInfo[2] != NULL) {
throw new \PDOException($errorInfo[0]);
}
//return array("found" => true, "errorInfo" => $errorInfo, "resultSet" => $result);
return $publicKey;
} catch (\PDOException $e) {
$pdo->rollback();
return array("found" => false, "errorInfo" => $e->getMessage());
}
//return false;
}
示例8: __destruct
/**
* 析构函数
*/
public function __destruct()
{
if (!self::$autocommit) {
$this->handler->rollback();
$this->handler->autocommit(true);
}
}
示例9: rollback
/**
* Annule la transaction ou bien revient au point de sauvegarde courant
* @return bool
*/
private function rollback()
{
if (--$this->transactionCounter) {
$this->pdolink->exec('ROLLBACK TO SAVEPOINT trans'.($this->transactionCounter + 1));
return true;
}
return $this->pdolink->rollback();
}
示例10: rollback
public function rollback()
{
if (--$this->transactionCounter) {
$this->exec('ROLLBACK TO trans' . $this->transactionCounter + 1);
return true;
}
return parent::rollback();
}
示例11: rollback
public function rollback()
{
if (--$this->transactionCounter) {
$this->exec('ROLLBACK TO ' . static::SAVEPOINT_PREFIX . $this->transactionCounter + 1);
return true;
}
return parent::rollback();
}
示例12: rollback
function rollback()
{
if ($this->transactionCounter >= 0) {
$this->transactionCounter = 0;
return parent::rollback();
}
$this->transactionCounter = 0;
return false;
}
示例13: RollbackTransaction
/**
* Rolls back a running transaction
*
* @access public
* @return Database
*/
public function RollbackTransaction() : Database
{
/* ------------------------------------------------------------------------------------------------------
ACT
------------------------------------------------------------------------------------------------------ */
self::$PDO->rollback();
/* ------------------------------------------------------------------------------------------------------
RETURN
------------------------------------------------------------------------------------------------------ */
return $this;
}
示例14: rollback
/**
* Wrapper for PDO's rollback.
*
* This wrapper will use ROLLBACK TO SAVEPOINT when a nested transaction is
* rolled back.
*
* This function will not attempt to auto-reconnect, because if the session
* has timed out, so has any active transaction, and thus an exception shall be
* raised.
*
* @see http://www.php.net/manual/en/pdo.rollback.php
*/
public function rollback()
{
if ($this->active_transactions == 0) {
throw new \RuntimeException('Rollback failed, no active transaction.');
}
$this->active_transactions -= 1;
if ($this->active_transactions == 0) {
return $this->pdo->rollback();
} else {
$this->pdo->exec(sprintf('ROLLBACK TO SAVEPOINT T%d', $this->active_transactions));
return true;
}
}
示例15: update
/**
* @see DataBackend::update()
* @throws DataBackendException
*/
public function update()
{
$useTA = false;
try {
$fileUtil = new FileUtil();
$fileBackend = new FileDataBackend(tempnam($fileUtil->getTempDirectory(), 'bav'));
//$fileBackend = new FileDataBackend('E:\xampp\htdocs\sepatool\external\bav\data\blz_2016_03_07_txt.txt');
$fileBackend->install();
$insertBank = $this->pdo->prepare("INSERT INTO {$this->prefix}bank\n (id, validator, mainAgency)\n VALUES(:bankID, :validator, :mainAgency)");
$insertAgency = $this->pdo->prepare("INSERT INTO {$this->prefix}agency\n (id, name, postcode, city, shortTerm, pan, bic, bank)\n VALUES (:id, :name, :postcode, :city, :shortTerm, :pan, :bic, :bank)");
try {
$this->pdo->beginTransaction();
$useTA = true;
} catch (\PDOException $e) {
trigger_error("Your DBS doesn't support transactions. Your data may be corrupted.");
}
$this->pdo->exec("DELETE FROM {$this->prefix}agency");
$this->pdo->exec("DELETE FROM {$this->prefix}bank");
foreach ($fileBackend->getAllBanks() as $bank) {
try {
$insertBank->execute(array(":bankID" => $bank->getBankID(), ":validator" => $bank->getValidationType(), ":mainAgency" => $bank->getMainAgency()->getID()));
$agencies = $bank->getAgencies();
$agencies[] = $bank->getMainAgency();
foreach ($agencies as $agency) {
$insertAgency->execute(array(":id" => $agency->getID(), ":name" => $agency->getName(), ":postcode" => $agency->getPostcode(), ":city" => $agency->getCity(), ":shortTerm" => $agency->getShortTerm(), ":bank" => $bank->getBankID(), ":pan" => $agency->hasPAN() ? $agency->getPAN() : null, ":bic" => $agency->hasBIC() ? $agency->getBIC() : null));
}
} catch (NoMainAgencyException $e) {
trigger_error("Skipping bank {$e->getBank()->getBankID()} without any main agency.");
}
}
// Update modification timestamp
$modificationStmt = $this->pdo->prepare("UPDATE {$this->prefix}meta SET value=:value WHERE name=:name");
$modificationStmt->execute(array(":name" => MetaData::LASTMODIFIED, ":value" => time()));
if ($useTA) {
$this->pdo->commit();
$useTA = false;
}
//$fileBackend->uninstall();
} catch (Exception $e) {
try {
if ($useTA) {
$this->pdo->rollback();
}
throw $e;
} catch (\PDOException $e2) {
throw new DataBackendIOException(get_class($e) . ": {$e->getMessage()}\nadditionally: {$e2->getMessage()}");
}
}
}