本文整理汇总了PHP中mysqli::rollback方法的典型用法代码示例。如果您正苦于以下问题:PHP mysqli::rollback方法的具体用法?PHP mysqli::rollback怎么用?PHP mysqli::rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mysqli
的用法示例。
在下文中一共展示了mysqli::rollback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @param string $sql
* @param array $queryParams
*
* @return bool|\mysqli_result
* @throws Mysql
*/
public function execute(string $sql, $queryParams = [])
{
// log the query
$this->log_sql($sql, $queryParams);
// start sql transaction
$this->mysqli->begin_transaction();
// use cache to get prepared statement
$statement = $this->get_statement_from_sql($sql);
// bind params
if (is_array($queryParams) && !empty($queryParams)) {
$bindTypes = '';
foreach ($queryParams as $name => $value) {
$bindTypes .= static::get_bind_type($value);
}
$statement->bind_param($bindTypes, ...$queryParams);
}
// execute statement
if (!$statement->execute()) {
$this->mysqli->rollback();
throw new Mysql($statement->error, $statement->errno, null, $sql);
}
// commit this transaction
$this->mysqli->commit();
// save info for latest query
$this->insertId = $statement->insert_id;
$this->affectedRows = $statement->affected_rows;
return $statement->get_result();
}
示例2: rollback
/**
* rollback transaction
*/
public function rollback()
{
if ($this->connection === null) {
$this->open();
}
$this->connection->rollback();
$this->connection->autocommit(true);
}
示例3: modificaCoche
function modificaCoche($coche)
{
//alert($coche->login);
global $servidor, $bd, $usuario, $contrasenia;
try {
@($db = new mysqli($servidor, $usuario, $contrasenia));
if (mysqli_connect_errno() != 0) {
throw new Exception('Error conectando:' . mysqli_connect_error(), mysqli_connect_errno());
}
$db->select_db($bd);
if ($db->errno != 0) {
throw new Exception('Error seleccionando bd:' . $db->error, $db->errno);
}
$consulta = "update coches set marca='" . $coche->marca . "', modelo='" . $coche->modelo . "', color='" . $coche->color . "' where matricula='" . $coche->matricula . "'";
if ($db->query($consulta) === false) {
throw new ExcepcionEnTransaccion();
}
$db->commit();
$db->close();
} catch (ExcepcionEnTransaccion $e) {
echo 'No se ha podido realizar la modificacion';
$db->rollback();
$db->close();
} catch (Exception $e) {
echo $e->getMessage();
if (mysqli_connect_errno() == 0) {
$db->close();
}
exit;
}
}
示例4: modificaAlumno
function modificaAlumno($alumno)
{
global $servidor, $bd, $usuario, $contrasenia;
try {
@($db = new mysqli($servidor, $usuario, $contrasenia));
if (mysqli_connect_errno() != 0) {
throw new Exception('Error conectando:' . mysqli_connect_error(), mysqli_connect_errno());
}
$db->select_db($bd);
if ($db->errno != 0) {
throw new Exception('Error seleccionando bd:' . $db->error, $db->errno);
}
$consulta = "update alumnos set password='" . $alumno->password . "', nombre='" . $alumno->nombre . "', apellido='" . $alumno->apellido . "', dni='" . $alumno->dni . "', email='" . $alumno->email . "', telefono=" . $alumno->telefono . ", sexo='" . $alumno->sexo . "' where login='" . $alumno->login . "'";
if ($db->query($consulta) === false) {
throw new ExcepcionEnTransaccion();
}
$db->commit();
$db->close();
} catch (ExcepcionEnTransaccion $e) {
echo 'No se ha podido realizar la modificacion';
$db->rollback();
$db->close();
} catch (Exception $e) {
echo $e->getMessage();
if (mysqli_connect_errno() == 0) {
$db->close();
}
exit;
}
}
示例5: rollback
/**
* Rolls back a transaction.
*
* @return Boolean
*/
public function rollback()
{
$this->connect();
if ($this->connected === TRUE) {
return $this->mysqli->rollback();
}
return FALSE;
}
示例6: rollback
function rollback()
{
if ($this->in_transaction > 0) {
parent::rollback();
$this->in_transaction = 0;
}
return $this->in_transaction;
}
示例7: rollback
public function rollback()
{
if ($this->logger != null)
{
$this->logger->log(Logger::LEVEL_TRACE, __FUNCTION__." called");
}
return $this->conn->rollback();
}
示例8: rollback
/**
* Rollback pending DB transactions.
*
* @return boolean true on success
*/
public function rollback()
{
$startTime = microtime(true);
$ret = $this->db->rollback();
//gather stats about queries
$this->addQueryTime(microtime(true) - $startTime);
return $ret;
}
示例9: rollBack
/**
* Rollback (abort) the transaction
* @throws MysqltcsException on rollback error
*/
public function rollBack()
{
if ($this->mysqliRef->rollback()) {
$this->log("rollback");
return;
}
$mex = "Mysql error: it is not possible perform the rollback. " . $this->mysqliRef->error;
$this->log($mex);
throw new MysqltcsException($mex);
}
示例10: rollback
/**
* Rollback a transaction.
*
* @returns \Docnet\DB
* @throws \Exception if we're not in a transaction
* @throws \Exception if the driver reports that the rollback failed
*/
public function rollback()
{
if (!$this->bol_in_transaction) {
throw new \Exception("Not in a transaction, can't rollback");
}
if (!$this->obj_db->rollback()) {
throw new \Exception("MySQL failed to rollback the transaction");
}
$this->bol_in_transaction = false;
return $this;
}
示例11: rollback
/**
* Rollback
*
* @throws Exception\RuntimeException
* @return $this
*/
public function rollback()
{
if (!$this->resource) {
throw new Exception\RuntimeException('Must be connected before you can rollback.');
}
if (!$this->inTransaction) {
throw new Exception\RuntimeException('Must call commit() before you can rollback.');
}
$this->resource->rollback();
return $this;
}
示例12: rollback
public function rollback()
{
if ($this->transactionCount == 0) {
return false;
}
if ($this->transactionCount == 1) {
$result = @$this->mysqli->rollback();
} else {
$result = @$this->mysqli->query('ROLLBACK TO point' . ($this->transactionCount - 1));
}
$this->popTransaction();
return $result;
}
示例13: rollback
/**
* {@inheritDoc}
*/
public function rollback()
{
if (!$this->isConnected()) {
throw new Exception\RuntimeException('Must be connected before you can rollback.');
}
if (!$this->inTransaction) {
throw new Exception\RuntimeException('Must call beginTransaction() before you can rollback.');
}
$this->resource->rollback();
$this->resource->autocommit(true);
$this->inTransaction = false;
return $this;
}
示例14: transactionRollback
/**
* Method to roll back a transaction.
*
* @param boolean $toSavepoint If true, rollback to the last savepoint.
*
* @return void
*
* @since 1.0
* @throws \RuntimeException
*/
public function transactionRollback($toSavepoint = false)
{
if (!$toSavepoint || $this->transactionDepth <= 1) {
$this->connect();
if ($this->connection->rollback()) {
$this->transactionDepth = 0;
}
return;
}
$savepoint = 'SP_' . ($this->transactionDepth - 1);
if ($this->executeUnpreparedQuery('ROLLBACK TO SAVEPOINT ' . $this->quoteName($savepoint))) {
$this->transactionDepth--;
}
}
示例15: compraProdotto
function compraProdotto($id, $email)
{
$mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
$mysqli->autocommit(false);
$add = $mysqli->query("INSERT INTO ordini (id_prodotto, nomeutente) VALUES ({$id}, '{$email}')");
$q = $mysqli->query("SELECT * FROM prodotti WHERE id={$id}");
if (!$add) {
$mysqli->rollback();
return false;
}
$prodottoSelezionato = mysqli_fetch_assoc($q);
if ($prodottoSelezionato['quantita'] == 0) {
$mysqli->rollback();
return false;
}
$nuovaQuantita = $prodottoSelezionato['quantita'] - 1;
$u = $mysqli->query("UPDATE prodotti SET quantita = {$nuovaQuantita} WHERE id={$id}");
if ($u) {
$mysqli->commit();
$mysqli->autocommit(true);
return true;
}
}