Skip to content

Commit fd1c1d9

Browse files
committed
Add Exec and Query methods to FakePDO, resolve some type issues by adding docblocks
1 parent ec0680b commit fd1c1d9

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

src/FakePdo.php

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace Vimeo\MysqlEngine;
33

4+
use PDO;
5+
46
class FakePdo extends \PDO
57
{
68
/**
@@ -70,9 +72,10 @@ public function getServer() : Server
7072
return $this->server;
7173
}
7274

73-
/**
74-
* @param string $statement
75-
*/
75+
/**
76+
* @param string $statement
77+
* @return Php7\FakePdoStatement|Php8\FakePdoStatement
78+
*/
7679
public function prepare($statement, $options = null)
7780
{
7881
if (\PHP_MAJOR_VERSION === 8) {
@@ -97,20 +100,59 @@ public function lastInsertId($seqname = null) : string
97100
return $this->lastInsertId;
98101
}
99102

103+
/**
104+
* @return bool
105+
*/
100106
public function beginTransaction()
101107
{
102108
Server::snapshot('transaction');
103109
return true;
104110
}
105111

112+
/**
113+
* @return bool
114+
*/
106115
public function commit()
107116
{
108117
return Server::deleteSnapshot('transaction');
109118
}
110119

120+
/**
121+
* @return bool
122+
* @throws Processor\ProcessorException
123+
*/
111124
public function rollback()
112125
{
113126
Server::restoreSnapshot('transaction');
114127
return true;
115128
}
129+
130+
/**
131+
* @param string $statement
132+
* @return bool
133+
*/
134+
public function exec($statement)
135+
{
136+
$statement = trim($statement);
137+
if (strpos($statement, 'SET ')===0){
138+
return false;
139+
}
140+
141+
$sth = $this->prepare($statement);
142+
return $sth->execute();
143+
}
144+
145+
/**
146+
* @param string $statement
147+
* @param int $mode
148+
* @param null $arg3
149+
* @param array $ctorargs
150+
* @return Php7\FakePdoStatement|Php8\FakePdoStatement
151+
*/
152+
public function query($statement, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = [])
153+
{
154+
$sth = $this->prepare($statement);
155+
$sth->execute();
156+
return $sth;
157+
}
116158
}

0 commit comments

Comments
 (0)