In PHP versions < 5.1cvs (as of date of this posting) this function actually returns FALSE on success and TRUE on error. This is because it was coded as a straight pass-thru wrapper to the MySQL api from MySQL a.b. and the mysql_commit() function in that api returns 0 on success and non-zero on failure.
Keep this in mind if you are checking the return value of this function.
mysqli_commit
mysqli->commit
(PHP 5)
mysqli->commit — Salva a transação atual
Descrição
Estilo de procedimento:
bool mysqli_commit
( object $link
)
Estilo orientado a objeto (metodo)
mysqli
bool
commit
( void
)
Grava a transação atual para a conexão com o banco de dados especificada pelo parâmetro link .
Valores de retorno
Retorna TRUE em caso de sucesso ou FALSE em falhas.
Veja também
Examplos
Example#1 Estilo orientado a objeto
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$mysqli->query("CREATE TABLE Language LIKE CountryLanguage Type=InnoDB");
/* set autocommit to off */
$mysqli->autocommit(FALSE);
/* Insert some values */
$mysqli->query("INSERT INTO Language VALUES ('DEU', 'Bavarian', 'F', 11.2)");
$mysqli->query("INSERT INTO Language VALUES ('DEU', 'Swabian', 'F', 9.4)");
/* commit transaction */
$mysqli->commit();
/* drop table */
$mysqli->query("DROP TABLE Language");
/* close connection */
$mysqli->close();
?>
Example#2 Estilo de procedimento
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "test");
/* check connection */
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* set autocommit to off */
mysqli_autocommit($link, FALSE);
mysqli_query($link, "CREATE TABLE Language LIKE CountryLanguage Type=InnoDB");
/* Insert some values */
mysqli_query($link, "INSERT INTO Language VALUES ('DEU', 'Bavarian', 'F', 11.2)");
mysqli_query($link, "INSERT INTO Language VALUES ('DEU', 'Swabian', 'F', 9.4)");
/* commit transaction */
mysqli_commit($link);
/* close connection */
mysqli_close($link);
?>
User Contributed Notes
mysqli_commit
mysqli_commit
mbedwards FROM gmail PERIOD com
03-Mar-2005 06:05
03-Mar-2005 06:05

mysqli_close