Comunitatea PHP Romania
 

 
mysqli_rollback

mysqli_rollback

(PHP 5)

mysqli_rollback

(no version information, might be only in CVS)

mysqli->rollback -- Rolls back current transaction

Description

bool mysqli_rollback ( object link)

class mysqli {

bool rollback ( void )

}

Rollbacks the current transaction for the database specified by the link parameter.

Return values

Returnează TRUE în caz de succes, FALSE în caz contrar.

Example

Exemplu 1. Object oriented style

<?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();
}

/* disable autocommit */
$mysqli->autocommit(FALSE);

$mysqli->query("CREATE TABLE myCity LIKE City");
$mysqli->query("ALTER TABLE myCity Type=InnoDB");
$mysqli->query("INSERT INTO myCity SELECT * FROM City LIMIT 50");

/* commit insert */
$mysqli->commit();

/* delete all rows */
$mysqli->query("DELETE FROM myCity");

if (
$result = $mysqli->query("SELECT COUNT(*) FROM myCity")) {
    
$row = $result->fetch_row();
    
printf("%d rows in table myCity.\n", $row[0]);
    
/* Free result */
    
$result->close();
}

/* Rollback */
$mysqli->rollback();

if (
$result = $mysqli->query("SELECT COUNT(*) FROM myCity")) {
    
$row = $result->fetch_row();
    
printf("%d rows in table myCity (after rollback).\n", $row[0]);
    
/* Free result */
    
$result->close();
}

/* Drop table myCity */
$mysqli->query("DROP TABLE myCity");

$mysqli->close();
?>

Exemplu 2. Procedural style

<?php
$link
= mysqli_connect("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
    
printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

/* disable autocommit */
mysqli_autocommit($link, FALSE);

mysqli_query($link, "CREATE TABLE myCity LIKE City");
mysqli_query($link, "ALTER TABLE myCity Type=InnoDB");
mysqli_query($link, "INSERT INTO myCity SELECT * FROM City LIMIT 50");

/* commit insert */
mysqli_commit($link);

/* delete all rows */
mysqli_query($link, "DELETE FROM myCity");

if (
$result = mysqli_query($link, "SELECT COUNT(*) FROM myCity")) {
    
$row = mysqli_fetch_row($result);
    
printf("%d rows in table myCity.\n", $row[0]);
    
/* Free result */
    
mysqli_free_result($result);
}

/* Rollback */
mysqli_rollback($link);

if (
$result = mysqli_query($link, "SELECT COUNT(*) FROM myCity")) {
    
$row = mysqli_fetch_row($result);
    
printf("%d rows in table myCity (after rollback).\n", $row[0]);
    
/* Free result */
    
mysqli_free_result($result);
}

/* Drop table myCity */
mysqli_query($link, "DROP TABLE myCity");

mysqli_close($link);
?>

The above examples would produce the following output:

0 rows in table myCity.
50 rows in table myCity (after rollback).

Ultimele discutii in forum RSS Forum

Ultimele articole Ultimele articole

Top membri

Pirahna Pirahna
la birou
carco carco
Bucuresti
Birkoff Birkoff
Bucuresti
Mascka Mascka
Braila
raul_ raul_
whooper whooper
Toronto ON
mihaitha mihaitha
Sibiu
gabysolomon gabysolomon
Bacau
oriceon oriceon
Constanta
garlicinicolae garlicinicolae

Newsletter


Email:
 inscriere
 renuntare
 
 Arhiva newsletter

Parteneriat

Copyright © 2001-2008 PHP Romania Add PHPRomania to Google Add PHPRomania to Del.icio.us Add PHPRomania to Stumbleupon Add PHPRomania to Yahoo! Add PHPRomania to Digg Add PHPRomania to Blink Mobile Phones | Loans | Debt | Samsung | Mortgages
Ads: Partener Way2Web Nework: gazduire web | inregistrare domenii | web design | imobiliare | web hosting
Powered by Simplis