|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2013-10-29 14:12 UTC] pedro at sancao dot com dot br
 Description:
------------
Using PDO on MySQL 5.5.32 (Linux and Windows)
When executing a prepared multi-query statement after calling PDO::beginTransaction() the PDO::commit() will return true but no commit will be done.
Also the affected tables will be locked until the database server is restarted.
Nor error is raised neither exception is thrown.
My tests was within a try/catch block.
Test script:
---------------
$pdo = new PDO('mysql:dbname=PLACE_DATABASE;host=localhost;charset=utf8', 'PLACE_USER', 'PLACE_PASSWORD', array(
	PDO::ATTR_PERSISTENT => true,
	PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
	PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ
));
try {
	$pdo->beginTransaction();
	$statement = $pdo->prepare('UPDATE ...; UPDATE ...; ');
	$statement->execute();
	$pdo->commit();
} catch (PDOException $e) {
	exit($e->getMessage());
	$pdo->rollBack();
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 07:00:01 2025 UTC | 
@uw@php.net Whats the meaning of beginTransaction() and commit() then? Adding those functions @PDO for single queries seems not "worth" to me. Or do you recommend to execute each query like?: function simpleExample(){ $dbh->beginTransaction(); $stmt = $dbh->prepare("INSERT INTO ..."); if(!$stmt->execute()){ $dbh->rollBack(); return false; } $stmt = $dbh->prepare("INSERT INTO ..."); if(!$stmt->execute()){ $dbh->rollBack(); return false; } $stmt = $dbh->prepare("INSERT INTO ..."); if(!$stmt->execute()){ $dbh->rollBack(); return false; } $dbh->commit(); return true; } And whats the security hole btw?