1212class PDODriver implements DriverInterface
1313{
1414 public readonly PDO $ pdo ;
15- protected static self $ instance ;
1615
1716 /**
1817 * @throws DriverException
@@ -49,7 +48,7 @@ public function connect(): void
4948 try {
5049 $ this ->pdo = new PDO ($ this ->dsn , $ this ->username , $ this ->password , $ this ->options );
5150 } catch (PDOException $ e ) {
52- throw new DriverException ($ e-> getMessage (), $ e -> getCode () );
51+ throw DriverException:: createFromPdo ($ e );
5352 }
5453 }
5554
@@ -62,4 +61,51 @@ public function isConnected(): bool
6261 {
6362 return isset ($ this ->pdo );
6463 }
64+
65+ /**
66+ * @throws DriverException
67+ */
68+ public function begin (): void
69+ {
70+ try {
71+ if (!$ this ->pdo ->beginTransaction ()) {
72+ throw new DriverException ('Failed to begin transaction. ' );
73+ }
74+ } catch (PDOException $ e ) {
75+ throw DriverException::createFromPdo ($ e );
76+ }
77+ }
78+
79+ /**
80+ * @throws DriverException
81+ */
82+ public function commit (): void
83+ {
84+ try {
85+ if (!$ this ->pdo ->commit ()) {
86+ throw new DriverException ('Failed to commit transaction. ' );
87+ }
88+ } catch (PDOException $ e ) {
89+ throw DriverException::createFromPdo ($ e );
90+ }
91+ }
92+
93+ /**
94+ * @throws DriverException
95+ */
96+ public function rollback (): void
97+ {
98+ try {
99+ if (!$ this ->pdo ->rollBack ()) {
100+ throw new DriverException ('Failed to rollback transaction. ' );
101+ }
102+ } catch (PDOException $ e ) {
103+ throw DriverException::createFromPdo ($ e );
104+ }
105+ }
106+
107+ public function inTransaction (): bool
108+ {
109+ return $ this ->pdo ->inTransaction ();
110+ }
65111}
0 commit comments