本文整理汇总了PHP中PDO::commit方法的典型用法代码示例。如果您正苦于以下问题:PHP PDO::commit方法的具体用法?PHP PDO::commit怎么用?PHP PDO::commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PDO
的用法示例。
在下文中一共展示了PDO::commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: commitTransaction
public function commitTransaction()
{
if (!$this->pdo->inTransaction()) {
throw new \RuntimeException('PDO is not in a transaction.');
}
$this->pdo->commit();
}
示例3: commit
public function commit()
{
if (--$this->transactionCounter === 0) {
return $this->pdo->commit();
}
return $this->transactionCounter >= 0;
}
示例4: commit
/**
* {@inheritdoc}
*/
public function commit()
{
$this->profiler->startQuery("COMMIT;");
$result = $this->pdo->commit();
$this->profiler->stopQuery();
return $result;
}
示例5: _logCompletedJob
private function _logCompletedJob(array $job)
{
$this->_pdo->beginTransaction();
$this->_pdo->prepare("INSERT INTO {$this->_table_log} (id,app_id,metric,value,distinct_id,created_at,sent_at) VALUES(?,?,?,?,?,?,?)")->execute(array($job['id'], $job['app_id'], $job['metric'], $job['value'], $job['distinct_id'], $job['created_at'], date("Y-m-d H:i:s")));
$this->_pdo->prepare("DELETE FROM {$this->_table_jobs} WHERE id = ? LIMIT 1")->execute(array($job['id']));
$this->_pdo->commit();
}
示例6: commit
public function commit()
{
if ($this->transactionsCount == 1) {
$this->pdo->commit();
}
--$this->transactionsCount;
}
示例7: 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();
}
}
示例8: commit
public function commit()
{
$this->transLevel--;
if (!$this->transactionNestable() || $this->transLevel == 0) {
$this->dbh->commit();
} else {
$this->dbh->exec(sprintf("RELEASE SAVEPOINT LEVEL%d", $this->transLevel));
}
}
示例9: close
public function close()
{
if (isset($this->dbh)) {
$options = $this->getOptions();
if ($options['transaction']) {
$this->dbh->commit();
}
unset($this->dbh);
}
}
示例10: 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();
}
}
示例11: commit
/**
* Valide la transaction ou bien libére le point de sauvegarde courant
* @return bool
*/
private function commit()
{
if (!--$this->transactionCounter) {
return $this->pdolink->commit();
}
else{
$this->pdolink->exec('RELEASE SAVEPOINT trans'.($this->transactionCounter + 1));
return true;
}
}
示例12: 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;
}
}
示例13: 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;
}
}
示例14: tearDown
/**
* This is run after each unit test. It empties the database.
*/
protected function tearDown()
{
// Only commit if the transaction hasn't failed.
// This is because tearDown() is also executed on a failed tests,
// and we don't want to call ConnectionInterface::commit() in that case
// since it will trigger an exception on its own
// ('Cannot commit because a nested transaction was rolled back')
if ($this->con->isCommitable()) {
$this->con->commit();
}
$this->con = null;
}
示例15: create
/**
* @param $post
* @return false|Post
*/
public function create($post)
{
$sql = "INSERT INTO posts (user_id, message , created_at ,updated_at) values (:user_id, :message, now(), now())";
$stmt = $this->dbh->prepare($sql);
$stmt->bindParam(':user_id', $post['user_id']);
$stmt->bindParam(':message', $post['message']);
$this->dbh->beginTransaction();
$stmt->execute();
$post = $this->findByID($this->dbh->lastInsertId());
$this->dbh->commit();
return $post;
}