function _DatabaseHandler::__construct

4.x _DatabaseHandler.php _DatabaseHandler::__construct()
5.x _DatabaseHandler.php _DatabaseHandler::__construct()
1 call to _DatabaseHandler::__construct()
_DatabaseHandler::__wakeup in classes/_DatabaseHandler.php
This function is called when this objectis unserialized. We want to reconnect to the database, so we'll call our constructor.

File

classes/_DatabaseHandler.php, line 10

Class

_DatabaseHandler

Code

function __construct() 
 {

  $db_host = @$GLOBALS ["fp_system_settings"]["db_host"];
  $db_port = @$GLOBALS ["fp_system_settings"]["db_port"];
  $db_user = @$GLOBALS ["fp_system_settings"]["db_user"];
  $db_pass = @$GLOBALS ["fp_system_settings"]["db_pass"];
  $db_name = @$GLOBALS ["fp_system_settings"]["db_name"];

  if ($db_host == "") {
    return; // some problem, do not proceed with the attempt to construct.
  }

  $db_host_ip = $db_host; // set as same as db_host for now.



  //$this->dbc = mysql_connect ($db_host, $db_user, $db_pass) or die('Could not connect to database: ' . mysql_error());
  //mysql_select_db ($db_name);

  // Connection by IP address is fastest, so let's always try to do that.
  // It can be time-consuming to convert our hostname to IP address.  Cache it in our SESSION
  if (isset($_SESSION ["fp_db_host_ip"])) {
    $db_host_ip = $_SESSION ["fp_db_host_ip"];
    if (!$db_host_ip) {
      $db_host_ip = $db_host;
    }
  }
  else {
    // Convert our db_host into an IP address, then save to simple SESSION cache.
    $db_host_ip = trim(gethostbyname($db_host));
    if (!$db_host_ip) {
      $db_host_ip = $db_host;
    }
    $_SESSION ["fp_db_host_ip"] = $db_host_ip;
  }

  // Connect using PDO
  if (!$this->pdo) {
    $this->pdo = new PDO("mysql:host=$db_host_ip;port=$db_port;dbname=$db_name;charset=utf8", $db_user, $db_pass, 
    array(
      PDO::MYSQL_ATTR_LOCAL_INFILE => true,
    ));
    // Set our error handling...  (using "silent" so I can catch errors in try/catch and display them, email, etc, if wanted.)
    $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


  }

}