/** * Get a database object * * Returns the global {@link JDatabase} object, only creating it * if it doesn't already exist. * * @param bool force (if true) the loading of the main J database, * needed in admin to connect to J db whilst still using fab db drivers "{package}" replacement text * * @param mixed, if null then loads the fabrik default connection, if an int then loads the specified connection by its id * * @return JDatabase object */ public static function getDbo($loadJoomlaDb = false, $cnnId = null) { $sig = (int) $loadJoomlaDb . '.' . $cnnId; if (!self::$database) { self::$database = array(); } if (!array_key_exists($sig, self::$database)) { JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_fabrik' . DS . 'tables'); $conf = JFactory::getConfig(); if (!$loadJoomlaDb) { $cn = JTable::getInstance('Connection', 'FabrikTable'); if (is_null($cnnId)) { $cn->load(array('default' => 1)); } else { $cn->load((int) $cnnId); } $host = $cn->host; $user = $cn->user; $password = $cn->password; $database = $cn->database; } else { $host = $conf->getValue('config.host'); $user = $conf->getValue('config.user'); $password = $conf->getValue('config.password'); $database = $conf->getValue('config.db'); } $dbprefix = $conf->getValue('config.dbprefix'); $driver = $conf->getValue('config.dbtype'); //test for sawpping db table names $driver .= '_fab'; $debug = $conf->getValue('config.debug'); $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $dbprefix); self::$database[$sig] = JDatabase::getInstance($options); } return self::$database[$sig]; }
/** * Get a database object * * Returns the global {@link JDatabase} object, only creating it * if it doesn't already exist. * * @param bool $loadJoomlaDb Force (if true) the loading of the main J database, * needed in admin to connect to J db whilst still using fab db drivers "{package}" * replacement text * * @param mixed $cnnId If null then loads the fabrik default connection, if an int then loads the * specified connection by its id * * @return JDatabaseDriver object */ public static function getDbo($loadJoomlaDb = false, $cnnId = null) { $sig = (int) $loadJoomlaDb . '.' . $cnnId; if (!self::$database) { self::$database = array(); } if (!array_key_exists($sig, self::$database)) { JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_fabrik/tables'); $conf = JFactory::getConfig(); if (!$loadJoomlaDb) { $cnModel = JModelLegacy::getInstance('Connection', 'FabrikFEModel'); $cn = $cnModel->getConnection($cnnId); $host = $cn->host; $user = $cn->user; $password = $cn->password; $database = $cn->database; } else { $host = $conf->get('host'); $user = $conf->get('user'); $password = $conf->get('password'); $database = $conf->get('db'); } $dbPrefix = $conf->get('dbprefix'); $driver = $conf->get('dbtype'); // Test for swapping db table names $driver .= '_fab'; $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $dbPrefix); $version = new JVersion(); self::$database[$sig] = $version->RELEASE > 2.5 ? JDatabaseDriver::getInstance($options) : JDatabase::getInstance($options); FabrikWorker::bigSelects(self::$database[$sig]); } return self::$database[$sig]; }
/** * Get a database object * * Returns the global {@link JDatabase} object, only creating it * if it doesn't already exist. * * @param bool $loadJoomlaDb Force (if true) the loading of the main J database, * needed in admin to connect to J db whilst still using fab db drivers "{package}" replacement text * * @param mixed $cnnId If null then loads the fabrik default connection, if an int then loads the specified connection by its id * * @return JDatabase object */ public static function getDbo($loadJoomlaDb = false, $cnnId = null) { $sig = (int) $loadJoomlaDb . '.' . $cnnId; if (!self::$database) { self::$database = array(); } if (!array_key_exists($sig, self::$database)) { JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_fabrik/tables'); $conf = JFactory::getConfig(); if (!$loadJoomlaDb) { $cnModel = JModelLegacy::getInstance('Connection', 'FabrikFEModel'); $cn = $cnModel->getConnection($cnnId); $host = $cn->host; $user = $cn->user; $password = $cn->password; $database = $cn->database; } else { $host = $conf->get('host'); $user = $conf->get('user'); $password = $conf->get('password'); $database = $conf->get('db'); } $dbprefix = $conf->get('dbprefix'); $driver = $conf->get('dbtype'); // Test for swapping db table names $driver .= '_fab'; $debug = $conf->get('debug'); $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $dbprefix); $version = new JVersion(); self::$database[$sig] = $version->RELEASE > 2.5 ? JDatabaseDriver::getInstance($options) : JDatabase::getInstance($options); /* * $$$ hugh - testing doing bigSelects stuff here * Reason being, some folk on shared hosting plans with very restrictive MySQL * setups are hitting the 'big selects' problem on Fabrik internal queries, not * just on their List specific queries. So we need to apply 'big selects' to our * default connection as well, essentially enabling it for ALL queries we do. */ $fbConfig = JComponentHelper::getParams('com_fabrik'); if ($fbConfig->get('enable_big_selects', 0) == '1') { $fabrikDb = self::$database[$sig]; /** * Use of OPTION in SET deprecated from MySQL 5.1. onward * http://www.fabrikar.com/forums/index.php?threads/enable-big-selects-error.39463/#post-198293 * NOTE - technically, using verison_compare on MySQL version could fail, if it's a "gamma" * release, which PHP desn't grok! */ if (version_compare($fabrikDb->getVersion(), '5.1.0', '>=')) { $fabrikDb->setQuery("SET SQL_BIG_SELECTS=1, GROUP_CONCAT_MAX_LEN=10240"); } else { $fabrikDb->setQuery("SET OPTION SQL_BIG_SELECTS=1, GROUP_CONCAT_MAX_LEN=10240"); } $fabrikDb->execute(); } } return self::$database[$sig]; }
/** * Get a database object * * Returns the global {@link JDatabase} object, only creating it * if it doesn't already exist. * * @param bool $loadJoomlaDb Force (if true) the loading of the main J database, * needed in admin to connect to J db whilst still using fab db drivers "{package}" replacement text * * @param mixed $cnnId If null then loads the fabrik default connection, if an int then loads the specified connection by its id * * @return JDatabase object */ public static function getDbo($loadJoomlaDb = false, $cnnId = null) { $sig = (int) $loadJoomlaDb . '.' . $cnnId; if (!self::$database) { self::$database = array(); } if (!array_key_exists($sig, self::$database)) { JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_fabrik/tables'); $conf = JFactory::getConfig(); if (!$loadJoomlaDb) { $cnModel = JModelLegacy::getInstance('Connection', 'FabrikFEModel'); $cn = $cnModel->getConnection($cnnId); $host = $cn->host; $user = $cn->user; $password = $cn->password; $database = $cn->database; } else { $host = $conf->get('host'); $user = $conf->get('user'); $password = $conf->get('password'); $database = $conf->get('db'); } $dbprefix = $conf->get('dbprefix'); $driver = $conf->get('dbtype'); // Test for swapping db table names $driver .= '_fab'; $debug = $conf->get('debug'); $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $dbprefix); $version = new JVersion(); self::$database[$sig] = $version->RELEASE > 2.5 ? JDatabaseDriver::getInstance($options) : JDatabase::getInstance($options); /* * $$$ hugh - testing doing bigSelects stuff here * Reason being, some folk on shared hosting plans with very restrictive MySQL * setups are hitting the 'big selects' problem on Fabrik internal queries, not * just on their List specific queries. So we need to apply 'big selects' to our * default connection as well, essentially enabling it for ALL queries we do. */ $fbConfig = JComponentHelper::getParams('com_fabrik'); if ($fbConfig->get('enable_big_selects', 0) == '1') { $fabrikDb = self::$database[$sig]; $fabrikDb->setQuery("SET OPTION SQL_BIG_SELECTS=1"); $fabrikDb->execute(); } } return self::$database[$sig]; }