Commit 71fecfda authored by screeper's avatar screeper

Add prefix feature

Set a prefix with the connection...
parent 0a03d83b
...@@ -19,6 +19,12 @@ class MysqliDb ...@@ -19,6 +19,12 @@ class MysqliDb
* @var MysqliDb * @var MysqliDb
*/ */
protected static $_instance; protected static $_instance;
/**
* Table prefix
*
* @var string
*/
protected $_prefix;
/** /**
* MySQLi instance * MySQLi instance
* *
...@@ -94,12 +100,13 @@ class MysqliDb ...@@ -94,12 +100,13 @@ class MysqliDb
* @param string $db * @param string $db
* @param int $port * @param int $port
*/ */
public function __construct($host, $username, $password, $db, $port = NULL) public function __construct($host, $username, $password, $db, $prefix = '', $port = NULL)
{ {
$this->host = $host; $this->host = $host;
$this->username = $username; $this->username = $username;
$this->password = $password; $this->password = $password;
$this->db = $db; $this->db = $db;
$this->prefix = $prefix;
if($port == NULL) if($port == NULL)
$this->port = ini_get ('mysqli.default_port'); $this->port = ini_get ('mysqli.default_port');
else else
...@@ -214,7 +221,7 @@ class MysqliDb ...@@ -214,7 +221,7 @@ class MysqliDb
$columns = '*'; $columns = '*';
$column = is_array($columns) ? implode(', ', $columns) : $columns; $column = is_array($columns) ? implode(', ', $columns) : $columns;
$this->_query = "SELECT $column FROM $tableName"; $this->_query = "SELECT $column FROM $this->_prefix$tableName";
$stmt = $this->_buildQuery($numRows); $stmt = $this->_buildQuery($numRows);
$stmt->execute(); $stmt->execute();
$this->_stmtError = $stmt->error; $this->_stmtError = $stmt->error;
...@@ -248,7 +255,7 @@ class MysqliDb ...@@ -248,7 +255,7 @@ class MysqliDb
*/ */
public function insert($tableName, $insertData) public function insert($tableName, $insertData)
{ {
$this->_query = "INSERT into $tableName"; $this->_query = "INSERT into $this->_prefix$tableName";
$stmt = $this->_buildQuery(null, $insertData); $stmt = $this->_buildQuery(null, $insertData);
$stmt->execute(); $stmt->execute();
$this->_stmtError = $stmt->error; $this->_stmtError = $stmt->error;
...@@ -267,7 +274,7 @@ class MysqliDb ...@@ -267,7 +274,7 @@ class MysqliDb
*/ */
public function update($tableName, $tableData) public function update($tableName, $tableData)
{ {
$this->_query = "UPDATE $tableName SET "; $this->_query = "UPDATE $this->_prefix$tableName SET ";
$stmt = $this->_buildQuery(null, $tableData); $stmt = $this->_buildQuery(null, $tableData);
$stmt->execute(); $stmt->execute();
...@@ -287,7 +294,7 @@ class MysqliDb ...@@ -287,7 +294,7 @@ class MysqliDb
*/ */
public function delete($tableName, $numRows = null) public function delete($tableName, $numRows = null)
{ {
$this->_query = "DELETE FROM $tableName"; $this->_query = "DELETE FROM $this->_prefix$tableName";
$stmt = $this->_buildQuery($numRows); $stmt = $this->_buildQuery($numRows);
$stmt->execute(); $stmt->execute();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment