Example #1
0
 /**
  * Load connection object
  *
  * @return	object	connection table
  */
 protected function loadConnection()
 {
     $params = $this->getParams();
     $id = $params->get('join_conn_id');
     $cid = $this->getlistModel()->getConnection()->getConnection()->id;
     if ($cid == $id) {
         $this->cn = $this->getlistModel()->getConnection();
     } else {
         $this->cn = JModelLegacy::getInstance('Connection', 'FabrikFEModel');
         $this->cn->setId($id);
     }
     return $this->cn->getConnection();
 }
Example #2
0
 /**
  * Load the connection associated with the table
  *
  * @return  object  database object using connection details false if connection error
  */
 public function &getDb()
 {
     if (!isset(self::$dbs)) {
         self::$dbs = array();
     }
     $error = false;
     $cn = $this->getConnection();
     $app = JFactory::getApplication();
     $input = $app->input;
     if ($input->get('task') == 'test') {
         self::$dbs = array();
         $this->connection = null;
         $cn = $this->getConnection();
     }
     if (!array_key_exists($cn->id, self::$dbs)) {
         if ($this->isJdb()) {
             $db = FabrikWorker::getDbo();
         } else {
             $options = $this->getConnectionOptions($cn);
             $db = $this->getDriverInstance($options);
         }
         try {
             $db->connect();
         } catch (RuntimeException $e) {
             $error = true;
         }
         self::$dbs[$cn->id] = $db;
         if ($error) {
             /**
              * $$$Rob - not sure why this is happening on badmintonrochelais.com (mySQL 4.0.24) but it seems like
              * you can only use one connection on the site? As JDatabase::getInstance() forces a new connection if its options
              * signature is not found, then fabrik's default connection won't be created, hence defaulting to that one
              */
             if ($cn->default == 1 && $input->get('task') !== 'test') {
                 self::$dbs[$cn->id] = FabrikWorker::getDbo();
                 // $$$rob remove the error from the error stack
                 // if we don't do this the form is not rendered
                 JError::getError(true);
             } else {
                 if (!$app->isAdmin()) {
                     throw new RuntimeException('Could not connection to database', E_ERROR);
                 } else {
                     // $$$ rob - unset the connection as caching it will mean that changes we make to the incorrect connection in admin, will not result
                     // in the test connection link informing the user that the changed connection properties are now correct
                     if ($input->get('task') == 'test') {
                         $this->connection = null;
                         $level = E_NOTICE;
                     } else {
                         $level = E_ERROR;
                     }
                     throw new RuntimeException('Could not connection to database cid = ' . $cn->id, $level);
                 }
             }
         }
     }
     return self::$dbs[$cn->id];
 }