note 116303 deleted from pdo.rollback by tularis
| From: | tularis@php.net | Date: | Tue, 09 Dec 2014 13:07:06 +0000 |
| Subject: | note 116303 deleted from pdo.rollback by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-201098@lists.php.net to get a copy of this message | ||
Note Submitter: mbf5923 at yahoo dot com
----
this can help you to use PDO::roolBack and PDO::commit:
for example:
i have a table in mysql database and table name is "tbl1"
in tbl1 i have tow columns ("id"=>integer,"name"=>char(25))
also i have another table as tbl2 and exactly like tbl1
now see command:
$link=new PDO("mysql:host=host;dbname=dbname", 'user', 'pass');
$query="INSERT INTO tbl1 (
id, name) VALUES (12,
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')";
$query2="INSERT INTO tbl2 (name) VALUES ('ali')";
$link->beginTransaction();
try{
$result = $link->exec($query);
$result2 = $link->exec($query2);
}catch(PDOException $e){
die($e->getMessage());
}
if($result2 && $result){
$link->commit();
}else{
$link->rollBack();
}