forked from bdewong/Zebra_Session
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[+]: add a interface && a wrapper class for the database-connection
- Loading branch information
Showing
5 changed files
with
191 additions
and
28 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
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,51 @@ | ||
<?php | ||
|
||
namespace voku\helper; | ||
|
||
interface Db4Session | ||
{ | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function close(); | ||
|
||
/** | ||
* @param mixed $var | ||
* | ||
* @return mixed | ||
*/ | ||
public function escape($var); | ||
|
||
/** | ||
* @param string $sql | ||
* @param string $string | ||
* | ||
* @return array|string <p>empty string on error</p> | ||
*/ | ||
public function fetchColumn($sql, $string); | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function ping(); | ||
|
||
/** | ||
* @param string $sql | ||
* | ||
* @return mixed|false <p>false on error</p> | ||
*/ | ||
public function query($sql); | ||
|
||
/** | ||
* @param string $string | ||
* | ||
* @return string | ||
*/ | ||
public function quote_string($string); | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function reconnect(); | ||
} |
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,102 @@ | ||
<?php | ||
|
||
namespace voku\helper; | ||
|
||
use voku\db\DB; | ||
|
||
class DbWrapper4Session implements Db4Session | ||
{ | ||
|
||
/** | ||
* @var DB | ||
*/ | ||
private $db; | ||
|
||
/** | ||
* SimpleMySQLiWrapper constructor. | ||
* | ||
* @param null|DB $db | ||
*/ | ||
public function __construct($db = null) | ||
{ | ||
if (null !== $db) { | ||
$this->db = $db; | ||
} else { | ||
$this->db = DB::getInstance(); | ||
} | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function close() | ||
{ | ||
return $this->db->close(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function escape($var) | ||
{ | ||
return $this->db->escape($var); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function fetchColumn($sql, $string) | ||
{ | ||
$result = $this->db->query($sql); | ||
|
||
return $result->fetchColumn($string); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function ping() | ||
{ | ||
return $this->db->ping(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function query($sql) | ||
{ | ||
return $this->db->query($sql); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function quote_string($string) | ||
{ | ||
return $this->db->quote_string($string); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function reconnect() | ||
{ | ||
return $this->db->reconnect(); | ||
} | ||
|
||
/** | ||
* @return DB | ||
*/ | ||
public function getDb() | ||
{ | ||
return $this->db; | ||
} | ||
|
||
/** | ||
* @return DbWrapper4Session | ||
*/ | ||
public static function getInstance() | ||
{ | ||
return new self(); | ||
} | ||
} |
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
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