当前位置: 首页>>代码示例>>PHP>>正文


PHP JDatabaseDriver::getInstance方法代码示例

本文整理汇总了PHP中JDatabaseDriver::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP JDatabaseDriver::getInstance方法的具体用法?PHP JDatabaseDriver::getInstance怎么用?PHP JDatabaseDriver::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JDatabaseDriver的用法示例。


在下文中一共展示了JDatabaseDriver::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct($config = array())
 {
     $udbPath = UserNotesHelper::userDataPath() . '/usernotes.db3';
     $db = JDatabaseDriver::getInstance(array('driver' => 'sqlite', 'database' => $udbPath));
     $config['dbo'] = $db;
     parent::__construct($config);
 }
开发者ID:ron4mac,项目名称:joomla_com_usernotes,代码行数:7,代码来源:edit.php

示例2: getOptions

 /**
  * Method to get the field options.
  *
  * @return   array    The field option objects.
  * @since    1.0
  */
 public function getOptions()
 {
     $params = JComponentHelper::getParams('com_sichtweiten');
     if ($params->get('extern_db')) {
         // Taken from https://docs.joomla.org/Connecting_to_an_external_database
         $option = array();
         $option['driver'] = $params->get('db_type', 'mysqli');
         $option['host'] = $params->get('db_host', 'localhost');
         $option['database'] = $params->get('db_database');
         $option['user'] = $params->get('db_user');
         $option['password'] = $params->get('db_pass');
         $option['prefix'] = $params->get('db_prefix', 'jos_');
         $db = JDatabaseDriver::getInstance($option);
     } else {
         $db = JFactory::getDbo();
     }
     $query = $db->getQuery(true);
     $query->select('a.id AS value');
     $query->from('#__sicht_sichtweite AS a');
     $query->order('a.id ASC');
     // Get the options.
     $db->setQuery($query);
     $options = $db->loadObjectList();
     foreach ($options as $option) {
         $option->text = JText::_('COM_SICHTWEITEN_SICHTWEITE_VALUE_' . $option->value);
         $option->class = 'tiefe sichtweite' . $option->value;
     }
     return $options;
 }
开发者ID:Bakual,项目名称:Sichtweiten,代码行数:35,代码来源:sichtweitenlist.php

示例3: getInstance

 /**
  * {@inheritdoc}
  *
  * @param   array $options Configuration options
  *
  * @return JDatabaseDriver
  *
  * @since 1.0
  */
 public static function getInstance($options = array())
 {
     $options['driver'] = isset($options['driver']) ? preg_replace('/[^A-Z0-9_\\.-]/i', '', $options['driver']) : 'mysqli';
     $options['database'] = isset($options['database']) ? $options['database'] : null;
     $options['select'] = isset($options['select']) ? $options['select'] : true;
     // Get an option hash to identify the instance
     $driverSignature = md5(serialize($options));
     // Check if the driver has been already instantiated
     if (empty(self::$instances[$driverSignature])) {
         // If the class doesn't exists, we cannot work with this driver.
         if (!self::isMySQL($options['driver'])) {
             // Let's using parent method
             return parent::getInstance($options);
         }
         // Let's create our driver instance using the options given.s
         try {
             /* @var $instance NenoDatabaseDriverMysqlx */
             $instance = new NenoDatabaseDriverMysqlx($options);
             $instance->refreshTranslatableTables();
         } catch (RuntimeException $ex) {
             throw new RuntimeException(sprintf('Unable to connect to the database. Error: %s', $ex->getMessage()));
         }
         // Save the instance into the instances set.
         self::$instances[$driverSignature] = $instance;
         // Load the tables configured to be translatable
         $instance->refreshTranslatableTables();
     }
     return self::$instances[$driverSignature];
 }
开发者ID:javigomez,项目名称:neno,代码行数:38,代码来源:driver.php

示例4: convertDb

 public static function convertDb($udbPath)
 {
     if (!file_exists($udbPath)) {
         return;
     }
     $attsDir = $udbPath . '/attach/';
     $db = JDatabaseDriver::getInstance(array('driver' => 'sqlite', 'database' => $udbPath . '/usernotes.db3'));
     $tbls = $db->getTableList();
     if (in_array('fileatt', $tbls)) {
         return;
     }
     // convert 'attached' table to 'fileatt' table with file sizes
     $db->setQuery('CREATE TABLE IF NOT EXISTS fileatt (contentID INTEGER NOT NULL, fsize INTEGER, attached TEXT)');
     $db->execute();
     $olds = $db->setQuery('SELECT * FROM attach')->loadAssocList();
     foreach ($olds as $old) {
         $atts = unserialize($old['attached']);
         foreach ($atts as $att) {
             $atfp = $old['contentID'] . '/' . $att;
             $atsz = file_exists($attsDir . $atfp) ? filesize($attsDir . $atfp) : 9999999999.0;
             $db->setQuery('INSERT INTO fileatt (contentID, fsize, attached) VALUES (' . $old['contentID'] . ', ' . $atsz . ', ' . $db->quote($att) . ')');
             //var_dump((string)$db);jexit();
             $db->execute();
         }
     }
     // remove the old 'attached table'
     //$db->setQuery('DROP TABLE IF EXISTS attach')->execute();
     // create view to sum the file sizes
     $db->setQuery('CREATE VIEW attsizsum AS SELECT SUM(fsize) AS totatt FROM fileatt');
     $db->execute();
     // add `secured` column to `notes`
     $db->setQuery('ALTER TABLE notes ADD COLUMN secured BOOLEAN DEFAULT NULL');
     $db->execute();
 }
开发者ID:ron4mac,项目名称:joomla_com_usernotes,代码行数:34,代码来源:db.php

示例5: 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;
 }
开发者ID:realityking,项目名称:jd12dk,代码行数:8,代码来源:web.php

示例6: getDBO

 /**
  * Method to get a JDatabaseDriver object.
  *
  * @param   string   $driver    The database driver to use.
  * @param   string   $host      The hostname to connect on.
  * @param   string   $user      The user name to connect with.
  * @param   string   $password  The password to use for connection authentication.
  * @param   string   $database  The database to use.
  * @param   string   $prefix    The table prefix to use.
  * @param   boolean  $select    True if the database should be selected.
  *
  * @return  JDatabaseDriver
  *
  * @since   1.6
  */
 public static function getDBO($driver, $host, $user, $password, $database, $prefix, $select = true)
 {
     static $db;
     if (!$db) {
         // Build the connection options array.
         $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix, 'select' => $select);
         // Get a database object.
         $db = JDatabaseDriver::getInstance($options);
     }
     return $db;
 }
开发者ID:educakanchay,项目名称:kanchay,代码行数:26,代码来源:database.php

示例7: setUp

	/**
	 * Sets up the fixture, for example, opens a network connection.
	 * This method is called before a test is executed.
	 *
	 * @return void
	 */
	protected function setUp()
	{

		$this->db = JDatabaseDriver::getInstance(
			array(
				'driver' => 'nosql',
				'database' => 'europa',
				'prefix' => '&',
			)
		);
	}
开发者ID:realityking,项目名称:joomla-platform,代码行数:17,代码来源:JDatabaseDriverTest.php

示例8: setUpBeforeClass

 /**
  * This method is called before the first test of this test class is run.
  *
  * An example DSN would be: dbname=//localhost:1521/joomla_ut;charset=AL32UTF8;user=utuser;pass=ut1234
  *
  * @return  void
  *
  * @since   12.1
  */
 public static function setUpBeforeClass()
 {
     // First let's look to see if we have a DSN defined or in the environment variables.
     if (defined('JTEST_DATABASE_ORACLE_DSN') || getenv('JTEST_DATABASE_ORACLE_DSN')) {
         $dsn = defined('JTEST_DATABASE_ORACLE_DSN') ? JTEST_DATABASE_ORACLE_DSN : getenv('JTEST_DATABASE_ORACLE_DSN');
     } else {
         return;
     }
     // First let's trim the oci: part off the front of the DSN if it exists.
     if (strpos($dsn, 'oci:') === 0) {
         $dsn = substr($dsn, 4);
     }
     // Split the DSN into its parts over semicolons.
     $parts = explode(';', $dsn);
     // Parse each part and populate the options array.
     foreach ($parts as $part) {
         list($k, $v) = explode('=', $part, 2);
         switch ($k) {
             case 'charset':
                 self::$_options['charset'] = $v;
                 break;
             case 'dbname':
                 $components = parse_url($v);
                 self::$_options['host'] = $components['host'];
                 self::$_options['port'] = $components['port'];
                 self::$_options['database'] = $components['path'];
                 break;
             case 'user':
                 self::$_options['user'] = $v;
                 break;
             case 'pass':
                 self::$_options['password'] = $v;
                 break;
         }
     }
     // Ensure some defaults.
     self::$_options['charset'] = isset(self::$_options['charset']) ? self::$_options['charset'] : 'AL32UTF8';
     self::$_options['port'] = isset(self::$_options['port']) ? self::$_options['port'] : 1521;
     try {
         // Attempt to instantiate the driver.
         self::$driver = JDatabaseDriver::getInstance(self::$_options);
     } catch (RuntimeException $e) {
         self::$driver = null;
     }
     // If for some reason an exception object was returned set our database object to null.
     if (self::$driver instanceof Exception) {
         self::$driver = null;
     }
     // Setup the factory pointer for the driver and stash the old one.
     self::$_stash = JFactory::$database;
     JFactory::$database = self::$driver;
 }
开发者ID:rvsjoen,项目名称:joomla-platform,代码行数:61,代码来源:oracle.php

示例9: 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;
 }
开发者ID:yatan,项目名称:JiGS-PHP-RPG-engine,代码行数:22,代码来源:cli.php

示例10: setUpBeforeClass

 /**
  * This method is called before the first test of this test class is run.
  *
  * An example DSN would be: host=localhost;dbname=joomla_ut;user=utuser;pass=ut1234
  *
  * @return  void
  *
  * @since   12.1
  */
 public static function setUpBeforeClass()
 {
     if (PHP_MAJOR_VERSION >= 7) {
         self::markTestSkipped('ext/mysql is unsupported on PHP 7.');
     }
     // First let's look to see if we have a DSN defined or in the environment variables.
     if (defined('JTEST_DATABASE_MYSQL_DSN') || getenv('JTEST_DATABASE_MYSQL_DSN')) {
         $dsn = defined('JTEST_DATABASE_MYSQL_DSN') ? JTEST_DATABASE_MYSQL_DSN : getenv('JTEST_DATABASE_MYSQL_DSN');
     } else {
         return;
     }
     // First let's trim the mysql: part off the front of the DSN if it exists.
     if (strpos($dsn, 'mysql:') === 0) {
         $dsn = substr($dsn, 6);
     }
     // Split the DSN into its parts over semicolons.
     $parts = explode(';', $dsn);
     // Parse each part and populate the options array.
     foreach ($parts as $part) {
         list($k, $v) = explode('=', $part, 2);
         switch ($k) {
             case 'host':
                 self::$_options['host'] = $v;
                 break;
             case 'dbname':
                 self::$_options['database'] = $v;
                 break;
             case 'user':
                 self::$_options['user'] = $v;
                 break;
             case 'pass':
                 self::$_options['password'] = $v;
                 break;
         }
     }
     try {
         // Attempt to instantiate the driver.
         self::$driver = JDatabaseDriver::getInstance(self::$_options);
     } catch (RuntimeException $e) {
         self::$driver = null;
     }
     // If for some reason an exception object was returned set our database object to null.
     if (self::$driver instanceof Exception) {
         self::$driver = null;
     }
     // Setup the factory pointer for the driver and stash the old one.
     self::$_stash = JFactory::$database;
     JFactory::$database = self::$driver;
 }
开发者ID:SysBind,项目名称:joomla-cms,代码行数:58,代码来源:mysql.php

示例11: setUp

 /**
  * Prepares the environment before running a test.
  *
  * @return  void
  *
  * @since   1.0
  *
  */
 protected function setUp()
 {
     parent::setUp();
     $this->saveFactoryState();
     JFactory::$session = $this->getMockSession();
     JFactory::$application = MockWebServiceApplicationWeb::create($this);
     $options = array('driver' => 'sqlite', 'database' => ':memory:', 'prefix' => 'ws_');
     $driver = JDatabaseDriver::getInstance($options);
     $pdo = new PDO('sqlite::memory:');
     $pdo->exec(file_get_contents(JPATH_TESTS . '/schema/ws.sql')) or die(print_r($pdo->errorInfo()));
     TestReflection::setValue($driver, 'connection', $pdo);
     JFactory::$database = $driver;
     $this->_instance = new WebServiceModelBase(new JContentFactory(), $driver);
     $this->_state = TestReflection::invoke($this->_instance, 'getState');
 }
开发者ID:prox91,项目名称:joomla-dev,代码行数:23,代码来源:baseTest.php

示例12: __construct

 /**
  * Constructor.
  *
  * @param   array $config An optional associative array of configuration settings.
  *
  * @see     JModelLegacy
  * @since   1.0
  */
 public function __construct($config = array())
 {
     $params = JComponentHelper::getParams('com_sichtweiten');
     if ($params->get('extern_db')) {
         // Taken from https://docs.joomla.org/Connecting_to_an_external_database
         $option = array();
         $option['driver'] = $params->get('db_type', 'mysqli');
         $option['host'] = $params->get('db_host', 'localhost');
         $option['database'] = $params->get('db_database');
         $option['user'] = $params->get('db_user');
         $option['password'] = $params->get('db_pass');
         $option['prefix'] = $params->get('db_prefix', 'jos_');
         $config['dbo'] = JDatabaseDriver::getInstance($option);
     }
     parent::__construct($config);
 }
开发者ID:Bakual,项目名称:Sichtweiten,代码行数:24,代码来源:visibilityreport.php

示例13: __construct

 public function __construct($config = array())
 {
     $this->_storPath = UserNotesHelper::userDataPath();
     $udbPath = $this->_storPath . '/usernotes.db3';
     $doInit = !file_exists($udbPath);
     $option = array('driver' => 'sqlite', 'database' => $udbPath);
     $db = JDatabaseDriver::getInstance($option);
     $db->connect();
     $db->getConnection()->sqliteCreateFunction('b64d', 'base64_decode', 1);
     if ($doInit) {
         require_once JPATH_COMPONENT . '/helpers/db.php';
         UserNotesHelperDb::buildDb($db);
     }
     $config['dbo'] = $db;
     parent::__construct($config);
 }
开发者ID:ron4mac,项目名称:joomla_com_usernotes,代码行数:16,代码来源:usernotes.php

示例14: register

 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container  $container  The DI container.
  *
  * @return  void
  *
  * @since   4.0
  */
 public function register(Container $container)
 {
     $container->alias('db', 'JDatabaseDriver')->alias('Joomla\\Database\\DatabaseInterface', 'JDatabaseDriver')->share('JDatabaseDriver', function (Container $container) {
         $conf = \JFactory::getConfig();
         $options = array('driver' => $conf->get('dbtype'), 'host' => $conf->get('host'), 'user' => $conf->get('user'), 'password' => $conf->get('password'), 'database' => $conf->get('db'), 'prefix' => $conf->get('dbprefix'));
         try {
             $db = \JDatabaseDriver::getInstance($options);
         } catch (\RuntimeException $e) {
             if (!headers_sent()) {
                 header('HTTP/1.1 500 Internal Server Error');
             }
             jexit('Database Error: ' . $e->getMessage());
         }
         $db->setDebug((bool) $conf->get('debug', false));
         return $db;
     }, true);
 }
开发者ID:Rai-Ka,项目名称:joomla-cms,代码行数:26,代码来源:Database.php

示例15: __construct

 /**
  * Constructor.
  *
  * @param   array $config An optional associative array of configuration settings.
  *
  * @see     JModelLegacy
  * @since   1.0
  */
 public function __construct($config = array())
 {
     $this->filter_fields = array('tp.name', 'tp.bemerkungen', 'g.displayName');
     $params = JFactory::getApplication()->getParams();
     if ($params->get('extern_db')) {
         // Taken from https://docs.joomla.org/Connecting_to_an_external_database
         $option = array();
         $option['driver'] = $params->get('db_type', 'mysqli');
         $option['host'] = $params->get('db_host', 'localhost');
         $option['database'] = $params->get('db_database');
         $option['user'] = $params->get('db_user');
         $option['password'] = $params->get('db_pass');
         $option['prefix'] = $params->get('db_prefix', 'jos_');
         $config['dbo'] = JDatabaseDriver::getInstance($option);
     }
     parent::__construct($config);
 }
开发者ID:Bakual,项目名称:Sichtweiten,代码行数:25,代码来源:locations.php


注:本文中的JDatabaseDriver::getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。