public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
cmsmadesimple-2-0 / lib / adodb.functions.php
100644 82 lines (68 sloc) 2.259 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
 
function load_adodb() {
  global $config;
  
  if ($config['debug'] == true)
  {
    require_once(cms_join_path(dirname(__FILE__), $config['use_adodb_lite'] == true ? 'adodb_lite' : 'adodb', 'adodb-errorpear.inc.php'));
  }
  
  define('ADODB_OUTP', 'debug_sql');
  
  $loaded_adodb = false;
  
  if ($config['use_adodb_lite'] == false || (isset($USE_OLD_ADODB) && $USE_OLD_ADODB == 1))
  {
  # CMSMS is configured to use full ADOdb
    $full_adodb = cms_join_path(dirname(__FILE__),'adodb','adodb.inc.php');
    if (! file_exists($full_adodb))
    {
      # Full ADOdb cannot be found, show a debug error message
      $gCms->errors[] = 'CMS Made Simple is configured to use the full ADOdb Database Abstraction library, but it\'s not in the lib' .DIRECTORY_SEPARATOR. 'adodb directory. Switched back to ADOdb Lite.';
    }
    else
    {
      # Load (full) ADOdb
      require($full_adodb);
      $loaded_adodb = true;
    }
  }
  if (!$loaded_adodb)
  {
    $adodb_light = cms_join_path(dirname(__FILE__),'adodb_lite','adodb.inc.php');
    # The ADOdb library is not yet included, try ADOdb Lite
    if (file_exists($adodb_light))
    {
      # Load ADOdb Lite
      require($adodb_light);
    }
    else
    {
      # ADOdb cannot be found, show a message and stop the script execution
      die('The ADOdb Lite database abstraction library cannot be found, CMS Made Simple cannot load.');
    }
  }
  
  #Define the CMS_ADODB_DT constant
  define('CMS_ADODB_DT', $config['use_adodb_lite'] ? 'DT' : 'T');
}
 
function & adodb_connect()
{
  global $db, $config;
  
  $dbinstance =& ADONewConnection($config['dbms'], 'pear:date:extend:transaction');
  $conn_func = (isset($config['persistent_db_conn']) && $config['persistent_db_conn'] == true) ? 'PConnect' : 'Connect';
  $connect_result = $dbinstance->$conn_func($config['db_hostname'], $config['db_username'], $config['db_password'], $config['db_name']);
  
  if (FALSE == $connect_result)
  {
    die('Database Connection failed');
  }
  
  $dbinstance->SetFetchMode(ADODB_FETCH_ASSOC);
  
  if ($config['debug'] == true)
  {
    $dbinstance->debug = true;
    #$dbinstance->LogSQL();
  }
  
  if ($config['dbms'] == 'sqlite')
  {
    $dbinstance->Execute('PRAGMA short_column_names = 1;');
    sqlite_create_function($cmsdb->_connectionID, 'now', 'time', 0);
  }
  
  $db =& $dbinstance;
  return $db;
}
 
?>