1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-05 06:07:32 +02:00

Support multiple database connections for the same mysql-user.

This commit is contained in:
Cameron
2017-03-31 10:51:21 -07:00
parent f4e3564c72
commit d110d8d4e9

View File

@@ -328,7 +328,10 @@ class e_db_mysql
$this->db_Set_Charset(); $this->db_Set_Charset();
$this->setSQLMode(); $this->setSQLMode();
if ($db_ConnectionID == NULL){ $db_ConnectionID = $this->mySQLaccess; } //if ($db_ConnectionID == NULL){
$db_ConnectionID = $this->mySQLaccess;
// }
return true; return true;
} }
@@ -347,18 +350,26 @@ class e_db_mysql
/** /**
* Select the database to use. * Select the database to use.
* @param string database name * @param string $database name
* @param string table prefix . eg. e107_ * @param string $table prefix . eg. e107_
* @param boolean $multiple set to maintain connection to a secondary database.
* @return boolean true when database selection was successful otherwise false. * @return boolean true when database selection was successful otherwise false.
*/ */
public function database($database, $prefix = MPREFIX) public function database($database, $prefix = MPREFIX, $multiple=false)
{ {
$this->mySQLdefaultdb = $database; $this->mySQLdefaultdb = $database;
$this->mySQLPrefix = $prefix; $this->mySQLPrefix = $prefix;
if($multiple === true)
{
$this->mySQLPrefix = "`".$database."`.".$prefix;
return true;
}
if($this->pdo) if($this->pdo)
{ {
try
try
{ {
$this->mySQLaccess->query("use ".$database); $this->mySQLaccess->query("use ".$database);
// $this->mySQLaccess->select_db($database); $dbh->query("use newdatabase"); // $this->mySQLaccess->select_db($database); $dbh->query("use newdatabase");
@@ -1816,7 +1827,8 @@ class e_db_mysql
$this->mySQLcurTable = $table; $this->mySQLcurTable = $table;
$this->tabset = true; $this->tabset = true;
} }
return ' `'.$this->mySQLPrefix.$table.'`'.substr($matches[0],-1);
return " ".$this->mySQLPrefix.$table.substr($matches[0],-1);
} }