-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhangjincheng
committed
Jun 5, 2019
1 parent
ecc9923
commit 1f8074f
Showing
2 changed files
with
108 additions
and
99 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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: 白猫 | ||
* Date: 2019/6/4 | ||
* Time: 18:31 | ||
*/ | ||
|
||
namespace ESD\Plugins\Mysql; | ||
|
||
|
||
use ESD\Psr\DB\DBInterface; | ||
use ReflectionClass; | ||
|
||
class Mysqli implements DBInterface | ||
{ | ||
/** | ||
* @var | ||
*/ | ||
private $_mysqli; | ||
|
||
private $_lastQuery; | ||
|
||
/** | ||
* Mysqli constructor. | ||
* @param $params | ||
* @throws \ReflectionException | ||
*/ | ||
public function __construct($params) | ||
{ | ||
$mysqlic = new ReflectionClass('mysqli'); | ||
$this->_mysqli = $mysqlic->newInstanceArgs($params); | ||
} | ||
|
||
public function __call($name, $arguments) | ||
{ | ||
$this->_lastQuery = json_encode($arguments); | ||
return $this->execute($name, function () use ($name, $arguments) { | ||
return call_user_func_array([$this->_mysqli, $name], $arguments); | ||
}); | ||
} | ||
|
||
public function __set($name, $value) | ||
{ | ||
$this->_mysqli->$name = $value; | ||
} | ||
|
||
public function __get($name) | ||
{ | ||
return $this->_mysqli->$name; | ||
} | ||
|
||
public function getType() | ||
{ | ||
return "mysqli"; | ||
} | ||
|
||
public function execute($name, callable $call = null) | ||
{ | ||
if ($call != null) { | ||
return $call(); | ||
} | ||
} | ||
|
||
public function getLastQuery() | ||
{ | ||
return $this->_lastQuery; | ||
} | ||
} |
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