File tree Expand file tree Collapse file tree 2 files changed +83
-1
lines changed Expand file tree Collapse file tree 2 files changed +83
-1
lines changed Original file line number Diff line number Diff line change @@ -532,6 +532,21 @@ static void pdo_mysql_request_shutdown(pdo_dbh_t *dbh)
532
532
}
533
533
/* }}} */
534
534
535
+ #ifdef PDO_USE_MYSQLND
536
+ # define pdo_mysql_get_server_status (m ) mysqlnd_get_server_status(m)
537
+ #else
538
+ # define pdo_mysql_get_server_status (m ) (m)->server_status
539
+ #endif
540
+
541
+ /* {{{ pdo_mysql_in_transaction */
542
+ static int pdo_mysql_in_transaction (pdo_dbh_t * dbh )
543
+ {
544
+ pdo_mysql_db_handle * H = (pdo_mysql_db_handle * )dbh -> driver_data ;
545
+ PDO_DBG_ENTER ("pdo_mysql_in_transaction" );
546
+ PDO_DBG_RETURN ((pdo_mysql_get_server_status (H -> server ) & SERVER_STATUS_IN_TRANS ) != 0 );
547
+ }
548
+ /* }}} */
549
+
535
550
/* {{{ mysql_methods */
536
551
static const struct pdo_dbh_methods mysql_methods = {
537
552
mysql_handle_closer ,
@@ -548,7 +563,7 @@ static const struct pdo_dbh_methods mysql_methods = {
548
563
pdo_mysql_check_liveness ,
549
564
NULL ,
550
565
pdo_mysql_request_shutdown ,
551
- NULL
566
+ pdo_mysql_in_transaction
552
567
};
553
568
/* }}} */
554
569
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ MySQL PDO class inTransaction
3
+ --SKIPIF--
4
+ <?php
5
+ require_once (__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc ' );
6
+ require_once (__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc ' );
7
+ MySQLPDOTest::skip ();
8
+ ?>
9
+ --FILE--
10
+ <?php
11
+ require_once (__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc ' );
12
+
13
+ const BEGIN = ['BEGIN ' , 'START TRANSACTION ' ];
14
+ const END = ['COMMIT ' , 'ROLLBACK ' ];
15
+
16
+ $ db = MySQLPDOTest::factory ();
17
+ // $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); // mysql does not support
18
+ for ($ b = 0 ; $ b < count (BEGIN ); $ b ++) {
19
+ for ($ e = 0 ; $ e < count (END ); $ e ++) {
20
+ foreach (['exec ' , 'query ' , 'execute ' ] as $ w ) {
21
+ foreach ([BEGIN [$ b ], END [$ e ]] as $ command ) {
22
+ switch ($ w ) {
23
+ case 'exec ' :
24
+ $ db ->exec ($ command );
25
+ break ;
26
+ case 'query ' :
27
+ $ db ->query ($ command )->execute ();
28
+ break ;
29
+ case 'execute ' :
30
+ /* EMULATE_PREPARES = QUERY */
31
+ $ db ->prepare ($ command )->execute ();
32
+ break ;
33
+ default :
34
+ assert (0 );
35
+ }
36
+ var_dump ($ db ->inTransaction ());
37
+ }
38
+ }
39
+ }
40
+ }
41
+
42
+ ?>
43
+ --EXPECT--
44
+ bool(true)
45
+ bool(false)
46
+ bool(true)
47
+ bool(false)
48
+ bool(true)
49
+ bool(false)
50
+ bool(true)
51
+ bool(false)
52
+ bool(true)
53
+ bool(false)
54
+ bool(true)
55
+ bool(false)
56
+ bool(true)
57
+ bool(false)
58
+ bool(true)
59
+ bool(false)
60
+ bool(true)
61
+ bool(false)
62
+ bool(true)
63
+ bool(false)
64
+ bool(true)
65
+ bool(false)
66
+ bool(true)
67
+ bool(false)
You can’t perform that action at this time.
0 commit comments