I’ve been using the DBLib PDO driver for connecting my PHP Symfony project with the MsSQL Database (where I need to query only 2 tables, Propel is set to connect with the MySQL database, which is main)
Unfortunately, I encountered problem, when a need to use transaction occured.
the following code
$pdo = new PDO('dblib:host=IP;dbname=DBNAME', 'login', 'password');
$pdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo -> beginTransaction();
$sql = "INSERT INTO DBNAME (Fields) VALUES (Values) ";
$query = $pdo -> prepare($sql);
$query -> execute();
$sql = "SELECT Field FROM DBNAME";
$query = $pdo -> prepare($sql);
$query -> execute();
$dane1 = $query -> fetchAll();
$pdo -> rollBack();
$sql = "SELECT Field FROM DBNAME";
$query = $pdo -> prepare($sql);
$query -> execute();
$dane2 = $query -> fetchAll();
I get such an error:
PDOException Object ( [message:protected] => This driver doesn't support transactions [string:Exception:private] => [code:protected] => 0
I’ve been looking for any other driver that would support the transaction, but unfortunately, i Couldn’t find anything except Microsoft Drivers 3.0 for PHP for SQL Server, which doesn’t apply to my issue, because my project is working on LAMP environment
If you can use PHP 5.4, transaction support was added for
PDODblibAlternatively, you could copy the
pdodblibfiles from 5.4 source to 5.3 and compile (they are nearly identical) or execute manual transaction queries.