/** * function getConnection * * Used to handle database connection. * Calls AMA_DB::connect() method and returns a reference to * the AMA_DB connection object created. * If $this->db already stores a connection object, then simply * return a reference to it. * * @return mixed $db - an AMA_DB connection object on success, * an AMA_Error object on failure. */ protected function &getConnection() { if ($this->db === AMA_DB_NOT_CONNECTED) { // ADALogger::log_db('Creating a new database connection '. $this->dsn); $db =& AMA_DB::connect($this->dsn); if (AMA_DB::isError($db)) { $retval = new AMA_Error(AMA_ERR_DB_CONNECTION); return $retval; } $this->db =& $db; } else { // ADALogger::log_db('Db già connesso '. $this->dsn . ' ' .$this->db->getDSN()); if ($this->dsn !== $this->db->getDSN()) { ADALogger::log_db('dsn diverso chiusura DB ' . $this->dsn . ' ' . $this->db->getDSN()); // Close existing datababse connection if (is_object($this->db) && method_exists($this->db, 'disconnect')) { ADALogger::log_db('Closing open connection to database ' . $this->db->getDSN()); $this->db->disconnect(); } // Open a new database connection $db =& AMA_DB::connect($this->dsn); if (AMA_DB::isError($db)) { return new AMA_Error(AMA_ERR_DB_CONNECTION); } $this->db =& $db; } } return $this->db; }