本文整理汇总了PHP中mysqli::commit方法的典型用法代码示例。如果您正苦于以下问题:PHP mysqli::commit方法的具体用法?PHP mysqli::commit怎么用?PHP mysqli::commit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mysqli
的用法示例。
在下文中一共展示了mysqli::commit方法的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: commit
/**
* commit transaction
*/
public function commit()
{
if ($this->connection === null) {
$this->open();
}
$this->connection->commit();
$this->connection->autocommit(true);
}
示例3: 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;
}
}
示例4: 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;
}
}
示例5: commit
public function commit()
{
if ($this->logger != null)
{
$this->logger->log(Logger::LEVEL_TRACE, __FUNCTION__." called");
}
return $this->conn->commit();
}
示例6: commit
function commit()
{
$this->in_transaction--;
if ($this->in_transaction == 0) {
parent::commit();
}
return $this->in_transaction;
}
示例7: commit
/**
* Commit
*/
public function commit()
{
if (!$this->resource) {
$this->connect();
}
$this->resource->commit();
$this->inTransaction = false;
}
示例8: commit
/**
* Commits a transaction.
*
* @return Boolean
*/
public function commit()
{
$this->connect();
if ($this->connected === TRUE) {
return $this->mysqli->commit();
}
return FALSE;
}
示例9: commit
/**
* Commits pending DB transactions.
*
* @return bool true on success
*/
public function commit()
{
$startTime = microtime(true);
$ret = $this->db->commit();
//gather stats about queries
$this->addQueryTime(microtime(true) - $startTime);
return $ret;
}
示例10: commit
/**
* Commit the transaction
* @throws MysqltcsException on commit error
*/
public function commit()
{
if ($this->mysqliRef->commit()) {
$this->log("commit");
return;
}
$mex = "Mysql error: it is not possible perform the commit. " . $this->mysqliRef->error;
$this->log($mex);
throw new MysqltcsException($mex);
}
示例11: commit
/**
* {@inheritDoc}
*/
public function commit()
{
if (!$this->isConnected()) {
$this->connect();
}
$this->resource->commit();
$this->inTransaction = false;
$this->resource->autocommit(true);
return $this;
}
示例12: transactionCommit
/**
* Method to commit a transaction.
*
* @param boolean $toSavepoint If true, commit to the last savepoint.
*
* @return void
*
* @since 1.0
* @throws \RuntimeException
*/
public function transactionCommit($toSavepoint = false)
{
if (!$toSavepoint || $this->transactionDepth <= 1) {
$this->connect();
if ($this->connection->commit()) {
$this->transactionDepth = 0;
}
return;
}
$this->transactionDepth--;
}
示例13: commit
/**
* Commit a transaction. If we're not in transaction, throw an exception.
* It's important that the calling code knows it's not in a transaction if
* the developer assumed that they were.
*
* @todo Are we scared that bol_in_transaction might get out of sync and
* prevent legit commits?
*
* @return \Docnet\DB
* @throws \Exception if we're not in a transaction
* @throws \Exception if the driver reports that the commit failed
*/
public function commit()
{
if (!$this->bol_in_transaction) {
throw new \Exception("Not in a transaction, can't commit");
}
if (!$this->obj_db->commit()) {
throw new \Exception("MySQL failed to commit the transaction");
}
$this->bol_in_transaction = false;
return $this;
}
示例14: commit
public function commit()
{
if ($this->transactionCount == 0) {
return false;
}
if ($this->transactionCount == 1) {
$result = @$this->mysqli->commit();
} else {
$result = @$this->mysqli->query('RELEASE SAVEPOINT point' . ($this->transactionCount - 1));
}
$this->popTransaction();
return $result;
}
示例15: db_insert
function db_insert($insert_query)
{
// Instantiate the mysqli class
$mysqli = new mysqli();
//Provide your DB credentials here
// Connect to the database server and select a database
$mysqli->connect('your db server', 'your db id', 'your password', 'your db name');
//Execute query
$result = $mysqli->query($insert_query);
//commit
$commit = $mysqli->commit();
// Close the connection
$mysqli->close();
}