You are here

function _cdn_advanced_get_db_connection in CDN 6.2

Same name and namespace in other branches
  1. 6 cdn.module \_cdn_advanced_get_db_connection()
  2. 7.2 cdn.advanced.inc \_cdn_advanced_get_db_connection()

Get a connection to the database.

Return value

A database connection (through PDO), or FALSE in case of failure.

3 calls to _cdn_advanced_get_db_connection()
cdn_advanced_get_servers in ./cdn.advanced.inc
Gets the servers on which a file is available when advanced mode is enabled.
cdn_get_domains in ./cdn.module
Get all domains from which files might be served. This information is necessary for some modules, e.g. Boost.
cdn_requirements in ./cdn.install
Implementation of hook_requirements().

File

./cdn.advanced.inc, line 62
Logic for advanced mode ("File Conveyor mode" in the UI).

Code

function _cdn_advanced_get_db_connection() {
  static $db;
  $synced_files_db = variable_get(CDN_ADVANCED_SYNCED_FILES_DB_VARIABLE, FALSE);
  if ($synced_files_db === FALSE || !file_exists($synced_files_db) || filesize($synced_files_db) == 0) {
    $db = FALSE;
  }
  elseif (!isset($db)) {
    try {
      $db = new PDO('sqlite:' . variable_get(CDN_ADVANCED_SYNCED_FILES_DB_VARIABLE, ''));
    } catch (PDOException $e) {
      watchdog('cdn', "Could not open synced files DB: %error.", array(
        '%error' => $e,
      ));
      $db = FALSE;
    }
  }
  return $db;
}