( ! ) Deprecated: Creation of dynamic property CSource::$validImageExtensions is deprecated in /home/saxon/teachers/com/mosstud/www/kod-exempel/oophp-test/Anax-oophp/src/CSource/CSource.php on line 42
Call Stack
#TimeMemoryFunctionLocation
10.0005363440{main}( ).../source.php:0
20.0038367880CSource->__construct( $options = ['secure_dir' => '..', 'base_dir' => '..'] ).../source.php:16

( ! ) Deprecated: Creation of dynamic property CSource::$spaces is deprecated in /home/saxon/teachers/com/mosstud/www/kod-exempel/oophp-test/Anax-oophp/src/CSource/CSource.php on line 43
Call Stack
#TimeMemoryFunctionLocation
10.0005363440{main}( ).../source.php:0
20.0038367880CSource->__construct( $options = ['secure_dir' => '..', 'base_dir' => '..'] ).../source.php:16

( ! ) Deprecated: Creation of dynamic property CSource::$ignore is deprecated in /home/saxon/teachers/com/mosstud/www/kod-exempel/oophp-test/Anax-oophp/src/CSource/CSource.php on line 44
Call Stack
#TimeMemoryFunctionLocation
10.0005363440{main}( ).../source.php:0
20.0038367880CSource->__construct( $options = ['secure_dir' => '..', 'base_dir' => '..'] ).../source.php:16

( ! ) Deprecated: Creation of dynamic property CSource::$secureDir is deprecated in /home/saxon/teachers/com/mosstud/www/kod-exempel/oophp-test/Anax-oophp/src/CSource/CSource.php on line 45
Call Stack
#TimeMemoryFunctionLocation
10.0005363440{main}( ).../source.php:0
20.0038367880CSource->__construct( $options = ['secure_dir' => '..', 'base_dir' => '..'] ).../source.php:16

( ! ) Deprecated: Creation of dynamic property CSource::$baseDir is deprecated in /home/saxon/teachers/com/mosstud/www/kod-exempel/oophp-test/Anax-oophp/src/CSource/CSource.php on line 46
Call Stack
#TimeMemoryFunctionLocation
10.0005363440{main}( ).../source.php:0
20.0038367880CSource->__construct( $options = ['secure_dir' => '..', 'base_dir' => '..'] ).../source.php:16

( ! ) Deprecated: Creation of dynamic property CSource::$queryPath is deprecated in /home/saxon/teachers/com/mosstud/www/kod-exempel/oophp-test/Anax-oophp/src/CSource/CSource.php on line 47
Call Stack
#TimeMemoryFunctionLocation
10.0005363440{main}( ).../source.php:0
20.0038367880CSource->__construct( $options = ['secure_dir' => '..', 'base_dir' => '..'] ).../source.php:16

( ! ) Deprecated: Creation of dynamic property CSource::$suggestedPath is deprecated in /home/saxon/teachers/com/mosstud/www/kod-exempel/oophp-test/Anax-oophp/src/CSource/CSource.php on line 48
Call Stack
#TimeMemoryFunctionLocation
10.0005363440{main}( ).../source.php:0
20.0038367880CSource->__construct( $options = ['secure_dir' => '..', 'base_dir' => '..'] ).../source.php:16

( ! ) Deprecated: Creation of dynamic property CSource::$realPath is deprecated in /home/saxon/teachers/com/mosstud/www/kod-exempel/oophp-test/Anax-oophp/src/CSource/CSource.php on line 49
Call Stack
#TimeMemoryFunctionLocation
10.0005363440{main}( ).../source.php:0
20.0038367880CSource->__construct( $options = ['secure_dir' => '..', 'base_dir' => '..'] ).../source.php:16

( ! ) Deprecated: Creation of dynamic property CSource::$pathinfo is deprecated in /home/saxon/teachers/com/mosstud/www/kod-exempel/oophp-test/Anax-oophp/src/CSource/CSource.php on line 50
Call Stack
#TimeMemoryFunctionLocation
10.0005363440{main}( ).../source.php:0
20.0038367880CSource->__construct( $options = ['secure_dir' => '..', 'base_dir' => '..'] ).../source.php:16

( ! ) Deprecated: Creation of dynamic property CSource::$file is deprecated in /home/saxon/teachers/com/mosstud/www/kod-exempel/oophp-test/Anax-oophp/src/CSource/CSource.php on line 66
Call Stack
#TimeMemoryFunctionLocation
10.0005363440{main}( ).../source.php:0
20.0038367880CSource->__construct( $options = ['secure_dir' => '..', 'base_dir' => '..'] ).../source.php:16

( ! ) Deprecated: Creation of dynamic property CSource::$extension is deprecated in /home/saxon/teachers/com/mosstud/www/kod-exempel/oophp-test/Anax-oophp/src/CSource/CSource.php on line 67
Call Stack
#TimeMemoryFunctionLocation
10.0005363440{main}( ).../source.php:0
20.0038367880CSource->__construct( $options = ['secure_dir' => '..', 'base_dir' => '..'] ).../source.php:16

( ! ) Deprecated: Creation of dynamic property CSource::$dir is deprecated in /home/saxon/teachers/com/mosstud/www/kod-exempel/oophp-test/Anax-oophp/src/CSource/CSource.php on line 68
Call Stack
#TimeMemoryFunctionLocation
10.0005363440{main}( ).../source.php:0
20.0038367880CSource->__construct( $options = ['secure_dir' => '..', 'base_dir' => '..'] ).../source.php:16

( ! ) Deprecated: Creation of dynamic property CSource::$path is deprecated in /home/saxon/teachers/com/mosstud/www/kod-exempel/oophp-test/Anax-oophp/src/CSource/CSource.php on line 69
Call Stack
#TimeMemoryFunctionLocation
10.0005363440{main}( ).../source.php:0
20.0038367880CSource->__construct( $options = ['secure_dir' => '..', 'base_dir' => '..'] ).../source.php:16

( ! ) Deprecated: Creation of dynamic property CSource::$breadcrumb is deprecated in /home/saxon/teachers/com/mosstud/www/kod-exempel/oophp-test/Anax-oophp/src/CSource/CSource.php on line 81
Call Stack
#TimeMemoryFunctionLocation
10.0005363440{main}( ).../source.php:0
20.0038367880CSource->__construct( $options = ['secure_dir' => '..', 'base_dir' => '..'] ).../source.php:16

( ! ) Deprecated: Creation of dynamic property CSource::$message is deprecated in /home/saxon/teachers/com/mosstud/www/kod-exempel/oophp-test/Anax-oophp/src/CSource/CSource.php on line 85
Call Stack
#TimeMemoryFunctionLocation
10.0005363440{main}( ).../source.php:0
20.0038367880CSource->__construct( $options = ['secure_dir' => '..', 'base_dir' => '..'] ).../source.php:16

( ! ) Deprecated: Creation of dynamic property CSource::$content is deprecated in /home/saxon/teachers/com/mosstud/www/kod-exempel/oophp-test/Anax-oophp/src/CSource/CSource.php on line 235
Call Stack
#TimeMemoryFunctionLocation
10.0005363440{main}( ).../source.php:0
20.0043371296CSource->View( ).../source.php:22
30.0047371616CSource->GetFileContent( ).../CSource.php:113

( ! ) Deprecated: Creation of dynamic property CSource::$encoding is deprecated in /home/saxon/teachers/com/mosstud/www/kod-exempel/oophp-test/Anax-oophp/src/CSource/CSource.php on line 166
Call Stack
#TimeMemoryFunctionLocation
10.0005363440{main}( ).../source.php:0
20.0043371296CSource->View( ).../source.php:22
30.0047371616CSource->GetFileContent( ).../CSource.php:113
40.0049380568CSource->DetectFileDetails( ).../CSource.php:236

( ! ) Deprecated: Creation of dynamic property CSource::$lineendings is deprecated in /home/saxon/teachers/com/mosstud/www/kod-exempel/oophp-test/Anax-oophp/src/CSource/CSource.php on line 181
Call Stack
#TimeMemoryFunctionLocation
10.0005363440{main}( ).../source.php:0
20.0043371296CSource->View( ).../source.php:22
30.0047371616CSource->GetFileContent( ).../CSource.php:113
40.0049380568CSource->DetectFileDetails( ).../CSource.php:236
Visa källkod | Anax en webbtemplate

Visa källkod

CDatabase.php

1 lines ASCII Unix (LF)
<?php
/**
 * Database wrapper, provides a database API for the framework but hides details of implementation.
 *
 */
class CDatabase {

  /**
   * Members
   */
  private $options;                   // Options used when creating the PDO object
  private $db   = null;               // The PDO object
  private $stmt = null;               // The latest statement used to execute a query
  private static $numQueries = 0;     // Count all queries made
  private static $queries = array();  // Save all queries for debugging purpose
  private static $params = array();   // Save all parameters for debugging purpose


  /**
   * Constructor creating a PDO object connecting to a choosen database.
   *
   * @param array $options containing details for connecting to the database.
   *
   */
  public function __construct($options) {
    $default = array(
      'dsn' => null,
      'username' => null,
      'password' => null,
      'driver_options' => null,
      'fetch_style' => PDO::FETCH_OBJ,
    );
    $this->options = array_merge($default, $options);

    $this->db = new PDO($this->options['dsn'], $this->options['username'], $this->options['password'], $this->options['driver_options']);
    $this->db->SetAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, $this->options['fetch_style']); 

    // Get debug information from session if any.
    if(isset($_SESSION['CDatabase'])) {
      self::$numQueries = $_SESSION['CDatabase']['numQueries'];
      self::$queries    = $_SESSION['CDatabase']['queries'];
      self::$params     = $_SESSION['CDatabase']['params'];
      unset($_SESSION['CDatabase']);
    }
  }
  
  
  /**
   * Getters
   */
  public function GetNumQueries() { return self::$numQueries; }
  public function GetQueries() { return self::$queries; }


  /**
   * Get a html representation of all queries made, for debugging and analysing purpose.
   * 
   * @return string with html.
   */
  public function Dump() {
    $html  = '<p><i>You have made ' . self::$numQueries . ' database queries.</i></p><pre>';
    foreach(self::$queries as $key => $val) {
      $params = empty(self::$params[$key]) ? null : htmlentities(print_r(self::$params[$key], 1), null, 'UTF-8') . '<br/><br/>';
      $html .= htmlentities($val, null, 'UTF-8') . '<br/><br/>' . $params;
    }
    return $html . '</pre>';
  }



  /**
   * Save debug information in session, useful as a flashmemory when redirecting to another page.
   * 
   * @param string $debug enables to save some extra debug information.
   */
  public function SaveDebug($debug=null) {
    if($debug) {
      self::$queries[] = $debug;
      self::$params[] = null;
    }

    self::$queries[] = 'Saved debuginformation to session.';
    self::$params[] = null;

    $_SESSION['CDatabase']['numQueries'] = self::$numQueries;
    $_SESSION['CDatabase']['queries']    = self::$queries;
    $_SESSION['CDatabase']['params']     = self::$params;
  }



  /**
   * Execute a select-query with arguments and return the resultset.
   * 
   * @param string $query the SQL query with ?.
   * @param array $params array which contains the argument to replace ?.
   * @param boolean $debug defaults to false, set to true to print out the sql query before executing it.
   * @param int $fetchStyle can be changed by sending in arguments.
   * @return array with resultset.
   */
  public function ExecuteSelectQueryAndFetchAll($query, $params=array(), $debug=false, $fetchStyle=null) {

    self::$queries[] = $query; 
    self::$params[]  = $params; 
    self::$numQueries++;

    if($debug) {
      echo "<p>Query = <br/><pre>{$query}</pre></p><p>Num query = " . self::$numQueries . "</p><p><pre>".print_r($params, 1)."</pre></p>";
    }

    $this->stmt = $this->db->prepare($query);
    $this->stmt->execute($params);
    return $this->stmt->fetchAll($fetchStyle);
  }


  /**
   * Execute a SQL-query and ignore the resultset.
   *
   * @param string $query the SQL query with ?.
   * @param array $params array which contains the argument to replace ?.
   * @param boolean $debug defaults to false, set to true to print out the sql query before executing it.
   * @return boolean returns TRUE on success or FALSE on failure. 
   */
  public function ExecuteQuery($query, $params = array(), $debug=false) {

    self::$queries[] = $query; 
    self::$params[]  = $params; 
    self::$numQueries++;

    if($debug) {
      echo "<p>Query = <br/><pre>".htmlentities($query)."</pre></p><p>Num query = " . self::$numQueries . "</p><p><pre>".htmlentities(print_r($params, 1))."</pre></p>";
    }

    $this->stmt = $this->db->prepare($query);
    $res = $this->stmt->execute($params);

    if(!$res) {
      echo "Error in executing query: " . $this->stmt->errorCode() . " " . htmlentities(print_r($this->stmt->errorInfo(), 1));
    }

    return $res;
  }


  /**
   * Return last insert id.
   */
  public function LastInsertId() {
    return $this->db->lastInsertid();
  }


  /**
   * Return rows affected of last INSERT, UPDATE, DELETE
   */
  public function RowCount() {
    return is_null($this->stmt) ? $this->stmt : $this->stmt->rowCount();
  }


}