-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from M1ke/master
Add Exec and Query methods to FakePDO
- Loading branch information
Showing
3 changed files
with
90 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,6 @@ www.pid | |
*~ | ||
composer.lock | ||
.vscode | ||
/.idea | ||
composer.phar | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,53 @@ | ||
<?php | ||
namespace Vimeo\MysqlEngine\Php7; | ||
|
||
class FakePdo extends \PDO implements \Vimeo\MysqlEngine\FakePdoInterface | ||
use PDO; | ||
use Vimeo\MysqlEngine\FakePdoInterface; | ||
use Vimeo\MysqlEngine\FakePdoTrait; | ||
|
||
class FakePdo extends PDO implements FakePdoInterface | ||
{ | ||
use \Vimeo\MysqlEngine\FakePdoTrait; | ||
use FakePdoTrait; | ||
|
||
/** | ||
* @param string $statement | ||
* @param ?array $options | ||
*/ | ||
public function prepare($statement, $options = null) | ||
/** | ||
* @param string $statement | ||
* @param array $options | ||
* @return FakePdoStatement | ||
*/ | ||
public function prepare($statement, array $options = []) | ||
{ | ||
return new FakePdoStatement($this, $statement, $this->real); | ||
} | ||
|
||
/** | ||
* @param string $statement | ||
* @return int|false | ||
*/ | ||
public function exec($statement) | ||
{ | ||
$statement = trim($statement); | ||
if (strpos($statement, 'SET ')===0){ | ||
return false; | ||
} | ||
|
||
$sth = $this->prepare($statement); | ||
if ($sth->execute()){ | ||
return $sth->rowCount(); | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @param string $statement | ||
* @param int $mode | ||
* @param null $arg3 | ||
* @param array $ctorargs | ||
* @return FakePdoStatement | ||
*/ | ||
public function query($statement, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) | ||
{ | ||
$sth = $this->prepare($statement); | ||
$sth->execute(); | ||
return $sth; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,52 @@ | ||
<?php | ||
namespace Vimeo\MysqlEngine\Php8; | ||
|
||
class FakePdo extends \PDO implements \Vimeo\MysqlEngine\FakePdoInterface | ||
use PDO; | ||
use Vimeo\MysqlEngine\FakePdoInterface; | ||
use Vimeo\MysqlEngine\FakePdoTrait; | ||
|
||
class FakePdo extends \PDO implements FakePdoInterface | ||
{ | ||
use \Vimeo\MysqlEngine\FakePdoTrait; | ||
use FakePdoTrait; | ||
|
||
/** | ||
* @param string $statement | ||
* @param ?array $options | ||
*/ | ||
public function prepare($statement, $options = null) | ||
/** | ||
* @param string $statement | ||
* @param array $options | ||
* @return FakePdoStatement | ||
*/ | ||
public function prepare($statement, array $options = []) | ||
{ | ||
return new FakePdoStatement($this, $statement, $this->real); | ||
} | ||
|
||
/** | ||
* @param string $statement | ||
* @return int|false | ||
*/ | ||
public function exec($statement) | ||
{ | ||
$statement = trim($statement); | ||
if (str_starts_with($statement, 'SET ')){ | ||
return false; | ||
} | ||
|
||
$sth = $this->prepare($statement); | ||
if ($sth->execute()){ | ||
return $sth->rowCount(); | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @param string $statement | ||
* @param int|null $mode | ||
* @param mixed ...$fetchModeArgs | ||
* @return FakePdoStatement | ||
*/ | ||
public function query(string $statement, ?int $mode = PDO::ATTR_DEFAULT_FETCH_MODE, mixed ...$fetchModeArgs) | ||
{ | ||
$sth = $this->prepare($statement); | ||
$sth->execute(); | ||
return $sth; | ||
} | ||
} |