You are here

function _cdn_advanced_get_db_connection in CDN 6

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

Get a connection to the database. The resulting PDO object is statically cached.

Return value

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

2 calls to _cdn_advanced_get_db_connection()
cdn_advanced_get_url in ./cdn.module
Gets the URL for a file when the basic mode is enabled.
cdn_requirements in ./cdn.module
Implementation of hook_requirements().

File

./cdn.module, line 418
Implementation of the core hooks, defines, public and private functions.

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', t("Could not open synced files DB: %error.", array(
        '%error' => $e,
      )));
      $db = FALSE;
    }
  }
  return $db;
}