PHP Portal » PHP Handbuch » mysqli::commit

Werbung

mysqli::commit


(PHP 5)

mysqli::commit -- mysqli_commitCommits the current transaction

Beschreibung

Object oriented style (method)

bool mysqli::commit ( void )

Procedural style:

bool mysqli_commit ( mysqli $link )

Commits the current transaction for the database connection.

Parameter-Liste

link

Nur bei prozeduralem Aufruf: Ein von mysqli_connect() oder mysqli_init() zurückgegebenes Verbindungsobjekt.

Rückgabewerte

Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben.

Beispiele

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$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();

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$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);

Siehe auch