Disable connection cache workaround

This commit is contained in:
kaetemi 2014-09-03 05:47:47 +02:00
parent a120179e75
commit d4423d956f

View file

@ -29,13 +29,13 @@
* *
*/ */
$PDOCache = array(); // $PDOCache = array();
class DBLayer { class DBLayer {
private $PDO; private $PDO;
private $host; // private $host;
private $dbname; // private $dbname;
/** /**
* The PDO object, instantiated by the constructor * The PDO object, instantiated by the constructor
@ -51,15 +51,15 @@ class DBLayer {
function __construct($db, $dbn = null) function __construct($db, $dbn = null)
{ {
global $cfg; global $cfg;
$this->host = $cfg['db'][$db]['host']; // $this->host = $cfg['db'][$db]['host'];
$this->dbname = $cfg['db'][$db]['name']; // $this->dbname = $cfg['db'][$db]['name'];
global $PDOCache; /*global $PDOCache;
if (isset($PDOCache[$this->host])) { if (isset($PDOCache[$this->host])) {
$this->PDO = $PDOCache[$this->host]['pdo']; $this->PDO = $PDOCache[$this->host]['pdo'];
} else { } else {*/
$dsn = "mysql:"; $dsn = "mysql:";
$dsn .= "host=" . $cfg['db'][$db]['host'] . ";"; $dsn .= "host=" . $cfg['db'][$db]['host'] . ";";
// $dsn .= "dbname=" . $cfg['db'][$db]['name'] . ";"; $dsn .= "dbname=" . $cfg['db'][$db]['name'] . ";"; // Comment this out when using the cache
$dsn .= "port=" . $cfg['db'][$db]['port'] . ";"; $dsn .= "port=" . $cfg['db'][$db]['port'] . ";";
$opt = array( $opt = array(
@ -68,11 +68,11 @@ class DBLayer {
PDO::ATTR_PERSISTENT => true PDO::ATTR_PERSISTENT => true
); );
$this->PDO = new PDO($dsn, $cfg['db'][$db]['user'], $cfg['db'][$db]['pass'], $opt); $this->PDO = new PDO($dsn, $cfg['db'][$db]['user'], $cfg['db'][$db]['pass'], $opt);
$PDOCache[$this->host] = array(); /* $PDOCache[$this->host] = array();
$PDOCache[$this->host]['pdo'] = $this->PDO; $PDOCache[$this->host]['pdo'] = $this->PDO;
$PDOCache[$this->host]['use'] = $this->dbname; $PDOCache[$this->host]['use'] = $this->dbname;
$this->PDO->query('USE ' . $this->dbname . ';'); // FIXME safety */ //$this->PDO->query('USE ' . $this->dbname . ';'); // FIXME safety
} /*}*/
} }
function __destruct() { function __destruct() {
@ -80,11 +80,11 @@ class DBLayer {
} }
function useDb() { function useDb() {
global $PDOCache; /*global $PDOCache;
if ($PDOCache[$this->host]['use'] != $this->dbname) { if ($PDOCache[$this->host]['use'] != $this->dbname) {
$PDOCache[$this->host]['use'] = $this->dbname; $PDOCache[$this->host]['use'] = $this->dbname;
$this->PDO->query('USE ' . $this->dbname . ';'); // FIXME safety $this->PDO->query('USE ' . $this->dbname . ';'); // FIXME safety
} }*/
} }
/** /**