function DatabaseHandler::__construct

6.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 11

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->pdo = $GLOBALS ['pdo']; // set in our settings.php file.

  /*
    // 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=utf8mb4", $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);
      
            
           
    }
  */

}