本文整理汇总了PHP中PDO::rollBack方法的典型用法代码示例。如果您正苦于以下问题:PHP PDO::rollBack方法的具体用法?PHP PDO::rollBack怎么用?PHP PDO::rollBack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PDO
的用法示例。
在下文中一共展示了PDO::rollBack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rollBack
/**
* {@inheritdoc}
*/
public function rollBack()
{
$this->profiler->startQuery("ROLLBACK;");
$result = $this->pdo->rollBack();
$this->profiler->stopQuery();
return $result;
}
示例2: runMigration
/**
* Выполняет запрос миграцию.
* @param string $migrationName имя миграции
* @param string $query запрос
* @param string $type тип миграции
* @return bool|\Exception|\PDOException
* @throw \RuntimeException в случае, если не удалось применить
*/
protected function runMigration($migrationName, $query, $type = 'up')
{
if (empty($query)) {
throw new \RuntimeException('В миграции отсутствует запрос');
}
try {
$this->db->beginTransaction();
$statement = $this->db->prepare($query);
$result = $statement->execute();
if (!$result) {
throw new \RuntimeException('Запрос не был выполнен');
}
$statement->closeCursor();
if ($type == 'up') {
$this->addMigrationInfo($migrationName);
} else {
$this->removeMigrationInfo($migrationName);
}
$this->db->commit();
} catch (\PDOException $e) {
$this->db->rollBack();
throw $e;
}
return true;
}
示例3: endTransaction
/**
* Ends a transaction with the server.
*
* @param bool $commit
* @return void
*/
public function endTransaction($commit = false)
{
if ($commit) {
$this->connection->commit();
} else {
$this->connection->rollBack();
}
}
示例4: rollBack
public function rollBack()
{
$this->transLevel--;
if (!$this->transactionNestable() || $this->transLevel == 0) {
$this->dbh->rollBack();
} else {
$this->dbh->exec(sprintf("ROLLBACK TO SAVEPOINT LEVEL%d", $this->transLevel));
}
}
示例5: __destruct
public function __destruct()
{
try {
if (!is_null($this->_conn)) {
$this->_conn->rollBack();
}
} catch (Exception $e) {
}
}
示例6: rollBack
public function rollBack()
{
if ($this->transactionsCount == 1) {
$this->transactionsCount = 0;
$this->pdo->rollBack();
} else {
--$this->transactionsCount;
}
}
示例7: rollBack
public function rollBack()
{
if ($this->transactionCounter >= 0) {
$this->transactionCounter = 0;
return $this->pdo->rollBack();
}
$this->transactionCounter = 0;
return false;
}
示例8: run
/**
* @param string $script
*/
public function run($script)
{
try {
$this->pdo->beginTransaction();
$this->pdo->query($script);
$this->pdo->commit();
} catch (\PDOException $e) {
$this->pdo->rollBack();
}
}
示例9: it_can_rollBack_on_error_during_update_user
public function it_can_rollBack_on_error_during_update_user(User $user)
{
$user->getUuid()->willReturn($uuid = Uuid::uuid4());
$user->getEmailAddress()->willReturn(EmailAddress::get($email = 'nute@gunray.tf'));
$user->getPassword()->willReturn($password = password_hash('no.jedi.please', PASSWORD_BCRYPT));
$user->getDisplayName()->willReturn($displayName = 'Nute Gunray');
$this->pdo->beginTransaction()->shouldBeCalled();
$exception = new \RuntimeException();
$this->pdo->prepare(new Argument\Token\StringContainsToken('UPDATE users'))->willThrow($exception);
$this->pdo->rollBack()->shouldBeCalled();
$this->shouldThrow($exception)->duringUpdate($user);
}
示例10: replaceTriplet
/**
* Replace current token after successful authentication
* @param $credential
* @param $token
* @param $persistentToken
* @param int $expire
*/
public function replaceTriplet($credential, $token, $persistentToken, $expire = 0)
{
try {
$this->connection->beginTransaction();
$this->cleanTriplet($credential, $persistentToken);
$this->storeTriplet($credential, $token, $persistentToken, $expire);
$this->connection->commit();
} catch (\PDOException $e) {
$this->connection->rollBack();
throw $e;
}
}
示例11: merge
/**
* @param $primaryPid
* @param $transferPid
*
* @return bool
*/
public function merge($primaryPid, $transferPid)
{
try {
$this->conn->beginTransaction();
foreach ($this->tables as $t) {
$this->conn->exec("UPDATE `{$t}` SET `pid` = '{$primaryPid}' WHERE `pid` = '{$transferPid}'");
}
$this->conn->exec("DELETE FROM `patient` WHERE `pid` = '{$transferPid}'");
$this->conn->commit();
return true;
} catch (Exception $e) {
error_log($e->getMessage());
$this->conn->rollBack();
return false;
}
}
示例12: doRollback
protected function doRollback( $fname = '' ) {
if ( $this->mTrxLevel == 0 ) {
return;
}
$this->mConn->rollBack();
$this->mTrxLevel = 0;
}
示例13: execute
/**
* @param String $query
* @param array $parameters
* @return int|null|string
*/
public function execute(string $query, $parameters = array())
{
try {
$this->pdo->beginTransaction();
$stmt = $this->pdo->prepare($query);
$stmt->execute($parameters);
if ($stmt->errorCode() != 0) {
$this->pdo->rollBack();
return 0;
}
$returnID = $this->pdo->lastInsertId();
$this->pdo->commit();
$stmt->closeCursor();
return $returnID;
} catch (\Exception $e) {
$this->log->addError("There was an error during a query: ", [$e->getMessage()]);
try {
$this->pdo = $this->connect();
} catch (\Exception $e2) {
$this->log->addCritical("Couldn't reconnect to the database: " . $e->getMessage());
die(1);
}
}
return null;
}
示例14: transactionRollBack
/**
* Rollback transaction
*/
public function transactionRollBack()
{
if (self::$transactionOngoing) {
self::$conn->rollBack();
self::$transactionOngoing = false;
}
}
示例15: executaSqlRetornoID
/**
* Execulta sentenças sql do tipo UPDATE, DELETE, INSERT, CREATE TABLE, etc.
*
* @param string $slq
* @return true - sucesso | false - falha
*/
public function executaSqlRetornoID($sql)
{
$this->ultimoID = null;
if (!$this->conectarNoBancoDeDados()) {
return false;
}
try {
$this->conexao->beginTransaction();
$this->resultado = $this->conexao->prepare($sql);
$this->resultado->execute();
if (!$this->resultado) {
$this->conexao->rollBack();
$this->desconectar();
return false;
}
} catch (PDOException $erro) {
$this->conexao->rollBack();
$this->desconectar();
return false;
}
$this->ultimoID = $this->conexao->lastInsertId();
$this->conexao->commit();
$this->desconectar();
return true;
}