Skip to content

Commit 0fbbed7

Browse files
author
Pantakan Chusri-eam
committed
Fix framework/db/schema/mssql/CMssqlPdoAdapter.php to use PDO native beginTransaction(), commit(), rollBack() on PHP >= 5.4
Implement inTransaction() for dblib to seperate behavior pre PHP 5.4 and later
1 parent 0fa8ca4 commit 0fbbed7

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Version 1.1.32 under development
66

77
- Enh #4587: Add socket connection support to `CRedisCache` (mateusmetzker)
88
- Bug #4591: Fix deprecation in `CCaptchaAction` for PHP 8.1+ (rob006)
9+
- Bug #4596: Fix transaction not commit when using dblib (icyzyy)
910

1011
Version 1.1.31 April 10, 2025
1112
--------------------------------

framework/db/schema/mssql/CMssqlPdoAdapter.php

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,48 +29,72 @@ public function lastInsertId ($sequence=NULL)
2929
return $this->query('SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS bigint)')->fetchColumn();
3030
}
3131

32+
/**
33+
* Checks if inside a transaction
34+
*
35+
* Checks if a transaction is currently active within the driver.
36+
* This method always true if PHP below 5.4.0 to make it able to exec 'COMMIT TRANSACTION'
37+
* @return boolean
38+
*/
39+
function inTransaction()
40+
{
41+
if(version_compare(PHP_VERSION,'5.4.0','>='))
42+
return parent::inTransaction();
43+
else
44+
return true;
45+
}
46+
3247
/**
3348
* Begin a transaction
3449
*
3550
* Is is necessary to override pdo's method, as mssql pdo drivers
36-
* does not support transaction
51+
* does not support transaction for PHP below 5.4.0
3752
*
3853
* @return boolean
3954
*/
4055
#[ReturnTypeWillChange]
4156
public function beginTransaction ()
4257
{
43-
$this->exec('BEGIN TRANSACTION');
58+
if(version_compare(PHP_VERSION,'5.4.0','>='))
59+
parent::beginTransaction();
60+
else
61+
$this->exec('BEGIN TRANSACTION');
4462
return true;
4563
}
4664

4765
/**
4866
* Commit a transaction
4967
*
5068
* Is is necessary to override pdo's method, as mssql pdo drivers
51-
* does not support transaction
69+
* does not support transaction for PHP below 5.4.0
5270
*
5371
* @return boolean
5472
*/
5573
#[ReturnTypeWillChange]
5674
public function commit ()
5775
{
58-
$this->exec('COMMIT TRANSACTION');
76+
if(version_compare(PHP_VERSION,'5.4.0','>='))
77+
parent::commit();
78+
else
79+
$this->exec('COMMIT TRANSACTION');
5980
return true;
6081
}
6182

6283
/**
6384
* Rollback a transaction
6485
*
6586
* Is is necessary to override pdo's method, ac mssql pdo drivers
66-
* does not support transaction
87+
* does not support transaction for PHP below 5.4.0
6788
*
6889
* @return boolean
6990
*/
7091
#[ReturnTypeWillChange]
7192
public function rollBack ()
7293
{
73-
$this->exec('ROLLBACK TRANSACTION');
94+
if(version_compare(PHP_VERSION,'5.4.0','>='))
95+
parent::rollBack();
96+
else
97+
$this->exec('ROLLBACK TRANSACTION');
7498
return true;
7599
}
76100
}

0 commit comments

Comments
 (0)