Skip to content

Commit

Permalink
Merge pull request #6 from M1ke/master
Browse files Browse the repository at this point in the history
Add Exec and Query methods to FakePDO
  • Loading branch information
muglug authored Feb 3, 2021
2 parents 7f247b2 + 0c3db93 commit 5d7c584
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ www.pid
*~
composer.lock
.vscode
/.idea
composer.phar
.phpunit.result.cache
51 changes: 44 additions & 7 deletions src/Php7/FakePdo.php
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;
}
}
50 changes: 43 additions & 7 deletions src/Php8/FakePdo.php
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;
}
}

0 comments on commit 5d7c584

Please sign in to comment.