當前位置: 首頁>>代碼示例>>PHP>>正文


PHP JDatabase::__construct方法代碼示例

本文整理匯總了PHP中JDatabase::__construct方法的典型用法代碼示例。如果您正苦於以下問題:PHP JDatabase::__construct方法的具體用法?PHP JDatabase::__construct怎麽用?PHP JDatabase::__construct使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在JDatabase的用法示例。


在下文中一共展示了JDatabase::__construct方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1:

 /**
  * Database object constructor
  *
  * @param	array	List of options used to configure the connection
  * @since	1.5
  * @see		JDatabase
  */
 function __construct($options)
 {
     $host = array_key_exists('host', $options) ? $options['host'] : 'localhost';
     $user = array_key_exists('user', $options) ? $options['user'] : '';
     $password = array_key_exists('password', $options) ? $options['password'] : '';
     $database = array_key_exists('database', $options) ? $options['database'] : '';
     $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : 'jos_';
     $select = array_key_exists('select', $options) ? $options['select'] : true;
     // Perform a number of fatality checks, then return gracefully
     if (!function_exists('mysql_connect')) {
         $this->_errorNum = 1;
         $this->_errorMsg = JText::_('JLIB_DATABASE_ERROR_ADAPTER_MYSQL');
         return;
     }
     // Connect to the server
     if (!($this->_connection = @mysql_connect($host, $user, $password, true))) {
         $this->_errorNum = 2;
         $this->_errorMsg = JText::_('JLIB_DATABASE_ERROR_CONNECT_MYSQL');
         return;
     }
     // Finalize initialisation
     parent::__construct($options);
     // Set sql_mode to non_strict mode
     mysql_query("SET @@SESSION.sql_mode = '';", $this->_connection);
     // select the database
     if ($select) {
         $this->select($database);
     }
 }
開發者ID:akksi,項目名稱:jcg,代碼行數:36,代碼來源:mysql.php

示例2:

 /**
  * Database object constructor
  *
  * @param	array	List of options used to configure the connection
  * @since	1.5
  * @see		JDatabase
  */
 function __construct($options)
 {
     $host = array_key_exists('host', $options) ? $options['host'] : 'localhost';
     $user = array_key_exists('user', $options) ? $options['user'] : '';
     $password = array_key_exists('password', $options) ? $options['password'] : '';
     $database = array_key_exists('database', $options) ? $options['database'] : '';
     $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : 'jos_';
     $select = array_key_exists('select', $options) ? $options['select'] : true;
     // Perform a number of fatality checks, then return gracefully
     if (!function_exists('mysql_connect')) {
         $this->_errorNum = 1;
         $this->_errorMsg = 'The MySQL adapter "mysql" is not available.';
         return;
     }
     // Connect to the server
     if (!($this->_connection = @mysql_connect($host, $user, $password, true))) {
         $this->_errorNum = 2;
         $this->_errorMsg = 'Could not connect to MySQL';
         return;
     }
     // Finalize initialisation
     parent::__construct($options);
     // select the database
     if ($select) {
         $this->select($database);
     }
 }
開發者ID:joebushi,項目名稱:joomla,代碼行數:34,代碼來源:mysql.php

示例3: __construct

 /**
  * This special constructor reuses the existing resource from the existing db connecton
  *
  * @param unknown_type $options
  */
 function __construct($options)
 {
     $db =& JFactory::getDBO();
     $select = array_key_exists('select', $options) ? $options['select'] : true;
     $database = array_key_exists('database', $options) ? $options['database'] : '';
     // perform a number of fatality checks, then return gracefully
     if (!function_exists('mysql_connect')) {
         $this->_errorNum = 1;
         $this->_errorMsg = 'The MySQL adapter "mysql" is not available.';
         return;
     }
     // connect to the server
     $this->_resource =& $db->_resource;
     // finalize initialization
     JDatabase::__construct($options);
     // select the database
     if ($select) {
         $this->select($database);
     }
 }
開發者ID:kaantunc,項目名稱:MYK-BOR,代碼行數:25,代碼來源:intercept.jdatabasemysql.php

示例4: __construct

 /**
  * Constructor.
  *
  * @param   array  $options  List of options used to configure the connection
  *
  * @return  void
  *
  * @since   11.1
  */
 protected function __construct($options)
 {
     // Get some basic values from the options.
     $options['host'] = isset($options['host']) ? $options['host'] : 'localhost';
     $options['user'] = isset($options['user']) ? $options['user'] : 'root';
     $options['password'] = isset($options['password']) ? $options['password'] : '';
     $options['database'] = isset($options['database']) ? $options['database'] : '';
     $options['select'] = isset($options['select']) ? (bool) $options['select'] : true;
     // Make sure the MySQL extension for PHP is installed and enabled.
     if (!function_exists('mysql_connect')) {
         // Legacy error handling switch based on the JError::$legacy switch.
         // @deprecated  11.3
         if (JError::$legacy) {
             $this->errorNum = 1;
             $this->errorMsg = JText::_('JLIB_DATABASE_ERROR_ADAPTER_MYSQL');
             return;
         } else {
             throw new DatabaseException(JText::_('JLIB_DATABASE_ERROR_ADAPTER_MYSQL'));
         }
     }
     // Attempt to connect to the server.
     if (!($this->connection = @mysql_connect($options['host'], $options['user'], $options['password'], true))) {
         // Legacy error handling switch based on the JError::$legacy switch.
         // @deprecated  11.3
         if (JError::$legacy) {
             $this->errorNum = 2;
             $this->errorMsg = JText::_('JLIB_DATABASE_ERROR_CONNECT_MYSQL');
             return;
         } else {
             throw new DatabaseException(JText::_('JLIB_DATABASE_ERROR_CONNECT_MYSQL'));
         }
     }
     // Finalize initialisation
     parent::__construct($options);
     // Set sql_mode to non_strict mode
     mysql_query("SET @@SESSION.sql_mode = '';", $this->connection);
     // If auto-select is enabled select the given database.
     if ($options['select'] && !empty($options['database'])) {
         $this->select($options['database']);
     }
 }
開發者ID:ramdesh,項目名稱:joomla-platform,代碼行數:50,代碼來源:mysql.php

示例5: __construct

 /**
  * This special constructor reuses the existing resource from the existing db connecton
  *
  * @param unknown_type $options
  */
 function __construct($options)
 {
     $db = JFactory::getDBO();
     // support for recovery of existing connections (Martin N. Brampton)
     if (isset($this->_options)) {
         $this->_options = $options;
     }
     $select = array_key_exists('select', $options) ? $options['select'] : true;
     $database = array_key_exists('database', $options) ? $options['database'] : '';
     // perform a number of fatality checks, then return gracefully
     if (!function_exists('mysqli_connect')) {
         $this->_errorNum = 1;
         $this->_errorMsg = 'The MySQL adapter "mysqli" is not available.';
         return;
     }
     // connect to the server
     $this->_resource = $db->_resource;
     // finalize initialization
     JDatabase::__construct($options);
     // select the database
     if ($select) {
         $this->select($database);
     }
 }
開發者ID:RangerWalt,項目名稱:ecci,代碼行數:29,代碼來源:intercept.jdatabasemysqli.php

示例6: __construct

 /**
  * Constructor.
  *
  * @param   array  $options  List of options used to configure the connection
  *
  * @return  void
  *
  * @since   11.1
  */
 protected function __construct($options)
 {
     // Get some basic values from the options.
     $options['host'] = isset($options['host']) ? $options['host'] : 'localhost';
     $options['user'] = isset($options['user']) ? $options['user'] : 'root';
     $options['password'] = isset($options['password']) ? $options['password'] : '';
     $options['database'] = isset($options['database']) ? $options['database'] : '';
     $options['select'] = isset($options['select']) ? (bool) $options['select'] : true;
     $options['port'] = null;
     $options['socket'] = null;
     /*
      * Unlike mysql_connect(), mysqli_connect() takes the port and socket as separate arguments. Therefore, we
      * have to extract them from the host string.
      */
     $tmp = substr(strstr($options['host'], ':'), 1);
     if (!empty($tmp)) {
         // Get the port number or socket name
         if (is_numeric($tmp)) {
             $options['port'] = $tmp;
         } else {
             $options['socket'] = $tmp;
         }
         // Extract the host name only
         $options['host'] = substr($options['host'], 0, strlen($options['host']) - (strlen($tmp) + 1));
         // This will take care of the following notation: ":3306"
         if ($options['host'] == '') {
             $options['host'] = 'localhost';
         }
     }
     // Make sure the MySQLi extension for PHP is installed and enabled.
     if (!function_exists('mysqli_connect')) {
         // Legacy error handling switch based on the JError::$legacy switch.
         // @deprecated  12.1
         if (JError::$legacy) {
             $this->errorNum = 1;
             $this->errorMsg = JText::_('JLIB_DATABASE_ERROR_ADAPTER_MYSQLI');
             return;
         } else {
             throw new JDatabaseException(JText::_('JLIB_DATABASE_ERROR_ADAPTER_MYSQLI'));
         }
     }
     // Attempt to connect to the server.
     if (!($this->connection = @mysqli_connect($options['host'], $options['user'], $options['password'], null, $options['port'], $options['socket']))) {
         // Legacy error handling switch based on the JError::$legacy switch.
         // @deprecated  12.1
         if (JError::$legacy) {
             $this->errorNum = 2;
             $this->errorMsg = JText::_('JLIB_DATABASE_ERROR_CONNECT_MYSQL');
             return;
         } else {
             throw new JDatabaseException(JText::_('JLIB_DATABASE_ERROR_CONNECT_MYSQL'));
         }
     }
     // Finalize initialisation
     parent::__construct($options);
     // Set sql_mode to non_strict mode
     mysqli_query($this->connection, "SET @@SESSION.sql_mode = '';");
     // If auto-select is enabled select the given database.
     if ($options['select'] && !empty($options['database'])) {
         $this->select($options['database']);
     }
 }
開發者ID:GMaup,項目名稱:joomla-platform,代碼行數:71,代碼來源:mysqli.php

示例7: __construct

 /**
  * Constructor.
  *
  * @param   array  $options  List of options used to configure the connection
  *
  * @since   11.1
  */
 protected function __construct($options)
 {
     // Get some basic values from the options.
     $options['host'] = isset($options['host']) ? $options['host'] : 'localhost';
     $options['user'] = isset($options['user']) ? $options['user'] : '';
     $options['password'] = isset($options['password']) ? $options['password'] : '';
     $options['database'] = isset($options['database']) ? $options['database'] : '';
     $options['select'] = isset($options['select']) ? (bool) $options['select'] : true;
     // Build the connection configuration array.
     $config = array('Database' => $options['database'], 'uid' => $options['user'], 'pwd' => $options['password'], 'CharacterSet' => 'UTF-8', 'ReturnDatesAsStrings' => true);
     // Make sure the SQLSRV extension for PHP is installed and enabled.
     if (!function_exists('sqlsrv_connect')) {
         // Legacy error handling switch based on the JError::$legacy switch.
         // @deprecated  12.1
         if (JError::$legacy) {
             $this->errorNum = 1;
             $this->errorMsg = JText::_('JLIB_DATABASE_ERROR_ADAPTER_SQLSRV');
             return;
         } else {
             throw new JDatabaseException(JText::_('JLIB_DATABASE_ERROR_ADAPTER_SQLSRV'));
         }
     }
     // Attempt to connect to the server.
     if (!($this->connection = @sqlsrv_connect($options['host'], $config))) {
         // Legacy error handling switch based on the JError::$legacy switch.
         // @deprecated  12.1
         if (JError::$legacy) {
             $this->errorNum = 2;
             $this->errorMsg = JText::_('JLIB_DATABASE_ERROR_CONNECT_SQLSRV');
             return;
         } else {
             throw new JDatabaseException(JText::_('JLIB_DATABASE_ERROR_CONNECT_SQLSRV'));
         }
     }
     // Make sure that DB warnings are not returned as errors.
     sqlsrv_configure('WarningsReturnAsErrors', 0);
     // Finalize initialisation
     parent::__construct($options);
     // If auto-select is enabled select the given database.
     if ($options['select'] && !empty($options['database'])) {
         $this->select($options['database']);
     }
 }
開發者ID:Arturogcalleja,項目名稱:herbolario,代碼行數:50,代碼來源:sqlsrv.php

示例8: substr

 /**
  * Database object constructor
  *
  * @param	array	List of options used to configure the connection
  * @since	1.5
  * @see		JDatabase
  */
 function __construct($options)
 {
     $host = array_key_exists('host', $options) ? $options['host'] : 'localhost';
     $user = array_key_exists('user', $options) ? $options['user'] : '';
     $password = array_key_exists('password', $options) ? $options['password'] : '';
     $database = array_key_exists('database', $options) ? $options['database'] : '';
     $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : 'jos_';
     $select = array_key_exists('select', $options) ? $options['select'] : true;
     // Unlike mysql_connect(), mysqli_connect() takes the port and socket
     // as separate arguments. Therefore, we have to extract them from the
     // host string.
     $port = NULL;
     $socket = NULL;
     $targetSlot = substr(strstr($host, ":"), 1);
     if (!empty($targetSlot)) {
         // Get the port number or socket name
         if (is_numeric($targetSlot)) {
             $port = $targetSlot;
         } else {
             $socket = $targetSlot;
         }
         // Extract the host name only
         $host = substr($host, 0, strlen($host) - (strlen($targetSlot) + 1));
         // This will take care of the following notation: ":3306"
         if ($host == '') {
             $host = 'localhost';
         }
     }
     // perform a number of fatality checks, then return gracefully
     if (!function_exists('mysqli_connect')) {
         $this->_errorNum = 1;
         $this->_errorMsg = JText::_('JLIB_DATABASE_ERROR_ADAPTER_MYSQLI');
         return;
     }
     // connect to the server
     if (!($this->_connection = @mysqli_connect($host, $user, $password, NULL, $port, $socket))) {
         $this->_errorNum = 2;
         $this->_errorMsg = JText::_('JLIB_DATABASE_ERROR_CONNECT_MYSQL');
         return;
     }
     // finalize initialization
     parent::__construct($options);
     // Set sqli_mode to non_strict mode
     mysqli_query($this->_connection, "SET @@SESSION.sql_mode = '';");
     // select the database
     if ($select) {
         $this->select($database);
     }
 }
開發者ID:akksi,項目名稱:jcg,代碼行數:56,代碼來源:mysqli.php

示例9:

 function __construct($host = 'localhost', $user, $pass, $db = '', $table_prefix = '', $offline = true)
 {
     parent::__construct('mysql', $host, $user, $pass, $db, $table_prefix);
 }
開發者ID:RangerWalt,項目名稱:ecci,代碼行數:4,代碼來源:database.php

示例10: __construct

 /**
  * Constructor.
  *
  * @param   array  $options  Array of database options with keys: host, user, password, database, select.
  *
  * @since   11.1
  */
 protected function __construct($options)
 {
     // Get some basic values from the options.
     $options['host'] = isset($options['host']) ? $options['host'] : 'localhost';
     $options['user'] = isset($options['user']) ? $options['user'] : 'root';
     $options['password'] = isset($options['password']) ? $options['password'] : '';
     $options['database'] = isset($options['database']) ? $options['database'] : '';
     $options['select'] = isset($options['select']) ? (bool) $options['select'] : true;
     // Make sure the PDO MySQL extension for PHP is installed and enabled.
     if (!class_exists('PDO')) {
         // Legacy error handling switch based on the JError::$legacy switch.
         // @deprecated  12.1
         if (JError::$legacy) {
             $this->errorNum = 1;
             $this->errorMsg = 'The PDO adapter "pdo" is not available.';
             return;
         } else {
             throw new JDatabaseException('The PDO adapter "pdo" is not available.');
         }
     }
     // Add extra configuration options as necessary
     $extras = array();
     if (isset($options['ssl_ca']) && $options['ssl_ca'] && $options['host'] != 'localhost') {
         $extras[PDO::MYSQL_ATTR_SSL_CA] = $options['ssl_ca'];
     }
     // Attempt to connect to the server.
     if (!($this->connection = new PDO("mysql:host={$options['host']}", $options['user'], $options['password'], $extras))) {
         // Legacy error handling switch based on the JError::$legacy switch.
         // @deprecated  12.1
         if (JError::$legacy) {
             $this->errorNum = 2;
             $this->errorMsg = JText::_('JLIB_DATABASE_ERROR_CONNECT_MYSQL');
             return;
         } else {
             throw new JDatabaseException(JText::_('JLIB_DATABASE_ERROR_CONNECT_MYSQL'));
         }
     }
     $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     // Finalize initialisation
     parent::__construct($options);
     // Set sql_mode to non_strict mode
     // mysql_query("SET @@SESSION.sql_mode = '';", $this->connection);
     // If auto-select is enabled select the given database.
     if ($options['select'] && !empty($options['database'])) {
         $this->select($options['database']);
     }
 }
開發者ID:mined-gatech,項目名稱:hubzero-cms,代碼行數:54,代碼來源:pdo.php

示例11: substr

 /**
  * Database object constructor
  *
  * @access	public
  * @param	array	List of options used to configure the connection
  * @since	1.5
  * @see		JDatabase
  */
 function __construct($options)
 {
     $host = array_key_exists('host', $options) ? $options['host'] : 'localhost';
     $user = array_key_exists('user', $options) ? $options['user'] : '';
     $password = array_key_exists('password', $options) ? $options['password'] : '';
     $database = array_key_exists('database', $options) ? $options['database'] : '';
     $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : 'jos_';
     $select = array_key_exists('select', $options) ? $options['select'] : true;
     // Unlike mysql_connect(), mysqli_connect() takes the port and socket
     // as separate arguments. Therefore, we have to extract them from the
     // host string.
     $port = NULL;
     $socket = NULL;
     $targetSlot = substr(strstr($host, ":"), 1);
     if (!empty($targetSlot)) {
         // Get the port number or socket name
         if (is_numeric($targetSlot)) {
             $port = $targetSlot;
         } else {
             $socket = $targetSlot;
         }
         // Extract the host name only
         $host = substr($host, 0, strlen($host) - (strlen($targetSlot) + 1));
         // This will take care of the following notation: ":3306"
         if ($host == '') {
             $host = 'localhost';
         }
     }
     // perform a number of fatality checks, then return gracefully
     if (!function_exists('mysqli_connect')) {
         $this->_errorNum = 1;
         $this->_errorMsg = 'The MySQL adapter "mysqli" is not available.';
         return;
     }
     // connect to the server
     if (!($this->_resource = @mysqli_connect($host, $user, $password, NULL, $port, $socket))) {
         $this->_errorNum = 2;
         $this->_errorMsg = 'Could not connect to MySQL';
         return;
     }
     // finalize initialization
     parent::__construct($options);
     // select the database
     if ($select) {
         $this->select($database);
     }
 }
開發者ID:esumerfd,項目名稱:ssol_joomla,代碼行數:55,代碼來源:mysqli.php


注:本文中的JDatabase::__construct方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。