Source for file database.php

Documentation is available at database.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Log
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Joomla! MySQL Database Log class
  14.  *
  15.  * This class is designed to output logs to a specific MySQL database table. Fields in this
  16.  * table are based on the Syslog style of log output. This is designed to allow quick and
  17.  * easy searching.
  18.  *
  19.  * @package     Joomla.Platform
  20.  * @subpackage  Log
  21.  * @since       11.1
  22.  */
  23. {
  24.     /**
  25.      * @var    string  The name of the database driver to use for connecting to the database.
  26.      * @since  11.1
  27.      */
  28.     protected $driver = 'mysqli';
  29.  
  30.     /**
  31.      * @var    string  The host name (or IP) of the server with which to connect for the logger.
  32.      * @since  11.1
  33.      */
  34.     protected $host = '127.0.0.1';
  35.  
  36.     /**
  37.      * @var    string  The database server user to connect as for the logger.
  38.      * @since  11.1
  39.      */
  40.     protected $user = 'root';
  41.  
  42.     /**
  43.      * @var    string  The password to use for connecting to the database server.
  44.      * @since  11.1
  45.      */
  46.     protected $password = '';
  47.  
  48.     /**
  49.      * @var    string  The name of the database table to use for the logger.
  50.      * @since  11.1
  51.      */
  52.     protected $database = 'logging';
  53.  
  54.     /**
  55.      * @var    string  The database table to use for logging entries.
  56.      * @since  11.1
  57.      */
  58.     protected $table = 'jos_';
  59.  
  60.     /**
  61.      * @var    JDatabaseDriver  The database driver object for the logger.
  62.      * @since  11.1
  63.      */
  64.     protected $db;
  65.  
  66.     /**
  67.      * Constructor.
  68.      *
  69.      * @param   array  &$options  Log object options.
  70.      *
  71.      * @since   11.1
  72.      */
  73.     public function __construct(array &$options)
  74.     {
  75.         // Call the parent constructor.
  76.         parent::__construct($options);
  77.  
  78.         // If both the database object and driver options are empty we want to use the system database connection.
  79.         if (empty($this->options['db_driver']))
  80.         {
  81.             $this->db = JFactory::getDbo();
  82.             $this->driver = null;
  83.             $this->host = null;
  84.             $this->user = null;
  85.             $this->password = null;
  86.             $this->database = null;
  87.             $this->prefix null;
  88.         }
  89.         else
  90.         {
  91.             $this->db null;
  92.             $this->driver (empty($this->options['db_driver'])) 'mysqli' $this->options['db_driver'];
  93.             $this->host (empty($this->options['db_host'])) '127.0.0.1' $this->options['db_host'];
  94.             $this->user (empty($this->options['db_user'])) 'root' $this->options['db_user'];
  95.             $this->password (empty($this->options['db_pass'])) '' $this->options['db_pass'];
  96.             $this->database (empty($this->options['db_database'])) 'logging' $this->options['db_database'];
  97.             $this->prefix (empty($this->options['db_prefix'])) 'jos_' $this->options['db_prefix'];
  98.         }
  99.  
  100.         // The table name is independent of how we arrived at the connection object.
  101.         $this->table (empty($this->options['db_table'])) '#__log_entries' $this->options['db_table'];
  102.     }
  103.  
  104.     /**
  105.      * Method to add an entry to the log.
  106.      *
  107.      * @param   JLogEntry  $entry  The log entry object to add to the log.
  108.      *
  109.      * @return  void 
  110.      *
  111.      * @since   11.1
  112.      */
  113.     public function addEntry(JLogEntry $entry)
  114.     {
  115.         // Connect to the database if not connected.
  116.         if (empty($this->db))
  117.         {
  118.             $this->connect();
  119.         }
  120.  
  121.         // Convert the date.
  122.         $entry->date = $entry->date->toSql(false$this->db);
  123.  
  124.         $this->db->insertObject($this->table$entry);
  125.     }
  126.  
  127.     /**
  128.      * Method to connect to the database server based on object properties.
  129.      *
  130.      * @return  void 
  131.      *
  132.      * @since   11.1
  133.      * @throws  RuntimeException
  134.      */
  135.     protected function connect()
  136.     {
  137.         // Build the configuration object to use for JDatabaseDriver.
  138.         $options array(
  139.             'driver' => $this->driver,
  140.             'host' => $this->host,
  141.             'user' => $this->user,
  142.             'password' => $this->password,
  143.             'database' => $this->database,
  144.             'prefix' => $this->prefix);
  145.  
  146.         $db JDatabaseDriver::getInstance($options);
  147.  
  148.         // Assign the database connector to the class.
  149.         $this->db $db;
  150.     }
  151. }

Documentation generated on Tue, 19 Nov 2013 14:57:47 +0100 by phpDocumentor 1.4.3