Commit c1d40ca6 authored by Alexander Butenko's avatar Alexander Butenko

Prefix should be static to be shareble with subqueries

parent 99909967
...@@ -24,7 +24,7 @@ class MysqliDb ...@@ -24,7 +24,7 @@ class MysqliDb
* *
* @var string * @var string
*/ */
protected $_prefix; protected static $_prefix;
/** /**
* MySQLi instance * MySQLi instance
* *
...@@ -116,14 +116,15 @@ class MysqliDb ...@@ -116,14 +116,15 @@ class MysqliDb
$this->port = ini_get ('mysqli.default_port'); $this->port = ini_get ('mysqli.default_port');
else else
$this->port = $port; $this->port = $port;
$this->setPrefix();
if ($host == null && $username == null && $db == null) { if ($host == null && $username == null && $db == null) {
$this->isSubQuery = true; $this->isSubQuery = true;
return; return;
} }
// for subqueries we do not need database connection and redefine root instance // for subqueries we do not need database connection and redefine root instance
$this->connect(); $this->connect();
$this->setPrefix();
self::$_instance = $this; self::$_instance = $this;
} }
...@@ -178,7 +179,7 @@ class MysqliDb ...@@ -178,7 +179,7 @@ class MysqliDb
*/ */
public function setPrefix($prefix = '') public function setPrefix($prefix = '')
{ {
$this->_prefix = $prefix; self::$_prefix = $prefix;
return $this; return $this;
} }
...@@ -246,7 +247,7 @@ class MysqliDb ...@@ -246,7 +247,7 @@ class MysqliDb
$columns = '*'; $columns = '*';
$column = is_array($columns) ? implode(', ', $columns) : $columns; $column = is_array($columns) ? implode(', ', $columns) : $columns;
$this->_query = "SELECT $column FROM $this->_prefix$tableName"; $this->_query = "SELECT $column FROM " .self::$_prefix . $tableName;
$stmt = $this->_buildQuery($numRows); $stmt = $this->_buildQuery($numRows);
if ($this->isSubQuery) if ($this->isSubQuery)
...@@ -291,7 +292,7 @@ class MysqliDb ...@@ -291,7 +292,7 @@ class MysqliDb
if ($this->isSubQuery) if ($this->isSubQuery)
return; return;
$this->_query = "INSERT into $this->_prefix$tableName"; $this->_query = "INSERT into " .self::$_prefix . $tableName;
$stmt = $this->_buildQuery(null, $insertData); $stmt = $this->_buildQuery(null, $insertData);
$stmt->execute(); $stmt->execute();
$this->_stmtError = $stmt->error; $this->_stmtError = $stmt->error;
...@@ -313,7 +314,7 @@ class MysqliDb ...@@ -313,7 +314,7 @@ class MysqliDb
if ($this->isSubQuery) if ($this->isSubQuery)
return; return;
$this->_query = "UPDATE $this->_prefix$tableName SET "; $this->_query = "UPDATE " . self::$_prefix . $tableName ." SET ";
$stmt = $this->_buildQuery(null, $tableData); $stmt = $this->_buildQuery(null, $tableData);
$stmt->execute(); $stmt->execute();
...@@ -336,7 +337,7 @@ class MysqliDb ...@@ -336,7 +337,7 @@ class MysqliDb
if ($this->isSubQuery) if ($this->isSubQuery)
return; return;
$this->_query = "DELETE FROM $this->_prefix$tableName"; $this->_query = "DELETE FROM " . self::$_prefix . $tableName;
$stmt = $this->_buildQuery($numRows); $stmt = $this->_buildQuery($numRows);
$stmt->execute(); $stmt->execute();
...@@ -397,7 +398,7 @@ class MysqliDb ...@@ -397,7 +398,7 @@ class MysqliDb
if ($joinType && !in_array ($joinType, $allowedTypes)) if ($joinType && !in_array ($joinType, $allowedTypes))
die ('Wrong JOIN type: '.$joinType); die ('Wrong JOIN type: '.$joinType);
$this->_join[$joinType . " JOIN " . $this->_prefix.$joinTable] = $joinCondition; $this->_join[$joinType . " JOIN " . self::$_prefix . $joinTable] = $joinCondition;
return $this; return $this;
} }
......
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