本文整理汇总了PHP中JFactory::database方法的典型用法代码示例。如果您正苦于以下问题:PHP JFactory::database方法的具体用法?PHP JFactory::database怎么用?PHP JFactory::database使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JFactory
的用法示例。
在下文中一共展示了JFactory::database方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setupDatabaseDriverOverride
function setupDatabaseDriverOverride()
{
//override only the override file exist
if (file_exists(dirname(__FILE__) . '/falang_database.php')) {
require_once dirname(__FILE__) . '/falang_database.php';
$conf = JFactory::getConfig();
$host = $conf->get('host');
$user = $conf->get('user');
$password = $conf->get('password');
$db = $conf->get('db');
$dbprefix = $conf->get('dbprefix');
$driver = $conf->get('dbtype');
$debug = $conf->get('debug');
$options = array('driver' => $driver, "host" => $host, "user" => $user, "password" => $password, "database" => $db, "prefix" => $dbprefix, "select" => true);
$db = new JFalangDatabase($options);
$db->debug($debug);
if ($db->getErrorNum() > 2) {
JError::raiseError('joomla.library:' . $db->getErrorNum(), 'JDatabase::getInstance: Could not connect to database <br/>' . $db->getErrorMsg());
}
// replace the database handle in the factory
JFactory::$database = null;
JFactory::$database = $db;
$test = JFactory::getDBO();
}
}
示例2: setUpBeforeClass
public static function setUpBeforeClass()
{
jimport('joomla.database.database');
jimport('joomla.database.table');
// Load the config if available.
@ include_once JPATH_TESTS . '/config.php';
if (class_exists('JTestConfig')) {
$config = new JTestConfig;
}
if (!is_object(self :: $dbo)) {
$options = array (
'driver' => isset ($config) ? $config->dbtype : 'mysql',
'host' => isset ($config) ? $config->host : '127.0.0.1',
'user' => isset ($config) ? $config->user : 'utuser',
'password' => isset ($config) ? $config->password : 'ut1234',
'database' => isset ($config) ? $config->db : 'joomla_ut',
'prefix' => isset ($config) ? $config->dbprefix : 'jos_'
);
self :: $dbo = JDatabase :: getInstance($options);
if (JError :: isError(self :: $dbo)) {
//ignore errors
define('DB_NOT_AVAILABLE', true);
}
}
self :: $database = JFactory :: $database;
JFactory :: $database = self :: $dbo;
}
示例3: setUp
/**
* Sets up the fixture.
*
* This method is called before a test is executed.
*
* @return void
*
* @since 11.1
*/
protected function setUp()
{
parent::setUp();
$this->saveFactoryState();
JFactory::$database = $this->getMockDatabase();
}
示例4: setUpDb
private function setUpDb()
{
$dbo = JDatabaseDriver::getInstance(array('driver' => 'sqlite', 'database' => '/Users/rouven/Sites/jd12dk/guestbook.sqlite'));
$dbo->setQuery('CREATE TABLE IF NOT EXISTS Comments (Id INTEGER PRIMARY KEY, Name TEXT, Email TEXT, Comment Text, Ip INTEGER, date TEXT)');
$dbo->execute();
// Inject database into JFactory
JFactory::$database = $dbo;
}
示例5: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @return void
*
* @since 3.0
*/
protected function setUp()
{
parent::setUp();
// Store the factory state so we can mock the necessary objects
$this->saveFactoryState();
JFactory::$database = $this->getMockDatabase('Mysqli');
// Register the object
$this->object = JSchemaChangeset::getInstance(JFactory::getDbo(), null);
}
示例6: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @return void
*
* @since 3.1
*/
protected function setUp()
{
parent::setUp();
// Store the factory state so we can mock the necessary objects
$this->saveFactoryState();
// Set up our mock database
JFactory::$database = $this->getMockDatabase('Mysqli');
FinderIndexerHelper::$stemmer = FinderIndexerStemmer::getInstance('porter_en');
}
示例7: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @return void
*
* @since 3.1
*/
protected function setUp()
{
parent::setUp();
$this->saveFactoryState();
JFactory::$application = $this->getMockCmsApp();
JFactory::$database = $this->getMockDatabase();
$this->backupServer = $_SERVER;
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['SCRIPT_NAME'] = '';
}
示例8: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @return void
*
* @since 3.1
*/
protected function setUp()
{
// Store the factory state so we can mock the necessary objects
$this->saveFactoryState();
// Set up our mock database
$db = JFactory::getDbo();
$db->name = 'mysqli';
JFactory::$database = $db;
FinderIndexerHelper::$stemmer = FinderIndexerStemmer::getInstance('porter_en');
}
示例9: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
// Store the factory state so we can mock the necessary objects
$this->saveFactoryState();
JFactory::$database = $this->getMockDatabase();
// Set up our mock database
$this->db = JFactory::getDbo();
$this->db->name = 'mysqli';
// Register the object
$this->object = JSchemaChangeset::getInstance($this->db, null);
}
示例10: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
parent::setUp();
// Store the factory state so we can mock the necessary objects
$this->saveFactoryState();
JFactory::$application = $this->getMockCmsApp();
JFactory::$database = $this->getMockDatabase('Mysqli');
JFactory::$session = $this->getMockSession();
// Register the object
$this->object = FinderIndexer::getInstance();
}
示例11: restoreFactoryState
/**
* Sets the Factory pointers
*
* @return void
*/
protected function restoreFactoryState()
{
\JFactory::$application = $this->savedFactoryState['application'];
\JFactory::$config = $this->savedFactoryState['config'];
\JFactory::$dates = $this->savedFactoryState['dates'];
\JFactory::$session = $this->savedFactoryState['session'];
\JFactory::$language = $this->savedFactoryState['language'];
\JFactory::$document = $this->savedFactoryState['document'];
\JFactory::$acl = $this->savedFactoryState['acl'];
\JFactory::$database = $this->savedFactoryState['database'];
\JFactory::$mailer = $this->savedFactoryState['mailer'];
}
示例12: onAfterInitialise
/**
* Method to register a custom database driver
*
* @return void
*/
public function onAfterInitialise()
{
$nenoLoader = JPATH_LIBRARIES . '/neno/loader.php';
if (file_exists($nenoLoader)) {
JLoader::register('NenoLoader', $nenoLoader);
// Register the Class prefix in the autoloader
NenoLoader::init();
// Load custom driver.
JFactory::$database = null;
JFactory::$database = NenoFactory::getDbo();
}
}
示例13: loadDatabase
/**
* Allows the application to load a custom or default database driver.
*
* @param JDatabaseDriver $driver An optional database driver object. If omitted, the application driver is created.
*
* @return JApplicationBase This method is chainable.
*
* @since 12.1
*/
public function loadDatabase(JDatabaseDriver $driver = null)
{
if ($driver === null) {
$this->db = JDatabaseDriver::getInstance(array('driver' => $this->get('db_driver'), 'host' => $this->get('db_host'), 'user' => $this->get('db_user'), 'password' => $this->get('db_pass'), 'database' => $this->get('db_name'), 'prefix' => $this->get('db_prefix')));
// Select the database.
$this->db->select($this->get('db_name'));
} else {
$this->db = $driver;
}
// Set the database to our static cache.
JFactory::$database = $this->db;
return $this;
}
示例14: __construct
/**
* Constructor: Deletes the default installation config file and recreates it with the good config file.
*
* @since 3.1
*/
public function __construct()
{
// Overrides application config and set the configuration.php file so tokens and database works.
JFactory::$config = null;
JFactory::getConfig(JPATH_SITE . '/configuration.php');
/*
* JFactory::getDbo() gets called during app bootup, and because of the "uniqueness" of the install app, the config doesn't get read
* correctly at that point. So, we have to reset the factory database object here so that we can get a valid database configuration.
* The day we have proper dependency injection will be a glorious one.
*/
JFactory::$database = null;
parent::__construct();
}
示例15: doExecute
/**
* Entry point for CLI script
*
* @return void
*
* @since 3.0
*/
public function doExecute()
{
$nenoLoader = JPATH_LIBRARIES . '/neno/loader.php';
if (file_exists($nenoLoader)) {
JLoader::register('NenoLoader', $nenoLoader);
// Register the Class prefix in the autoloader
NenoLoader::init(false);
// Load custom driver.
JFactory::$database = null;
JFactory::$database = NenoFactory::getDbo();
}
NenoTaskMonitor::runTask();
}