GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

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
tedkulp (author)
Sun Sep 09 01:09:55 -0700 2007
commit  4978453c6368fd40690312e742cc2d7c095cec3a
tree    fbf2395a0e194d61b692bdc9467e422e717629fb
parent  a11ef674ead2618eb15652709b18c9aa06e5c4f0
cmsmadesimple-2-0 / lib / adodb.functions.php
100644 97 lines (80 sloc) 2.818 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
 
function load_adodb()
{
  global $config, $ADODB_vers;
 
  // @TODO: Remove dependence on PEAR for error handling  
  if ($config['debug'] == true)
  {
    #@include_once(cms_join_path(dirname(__FILE__), $config['use_adodb_lite'] == true ? 'adodb_lite' : 'adodb', 'adodb-errorpear.inc.php'));
  }
  
  define('ADODB_OUTP', 'debug_sql');
  //define('ADODB_ERROR_HANDLER', 'adodb_error');
  
  $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('CMS_ADODB_DT', $config['use_adodb_lite'] ? 'DT' : 'T');
}
 
function & adodb_connect()
{
  global $config;
  
  $dbinstance =& ADONewConnection($config['dbms'], 'pear:date:extend:transaction');
  $dbinstance->raiseErrorFn = "adodb_error";
  $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();
  }
 
  $dbinstance->raiseErrorFn = null;
  
  $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($config['use_adodb_lite'] ? $db->connectionId : $db->_connectionID, 'now', 'time', 0);
  }
  
  $db =& $dbinstance;
  return $db;
}
 
function adodb_error($dbtype, $function_performed, $error_number, $error_message, $host, $database, &$connection_obj)
{
  echo "<strong>Database Connection Failed</strong><br />";
  echo "Error: {$error_message} ({$error_number})<br />";
  echo "Function Performed: {$function_performed}<br />";
  echo "Host/DB: {$host}/{$database}<br />";
  echo "Database Type: {$dbtype}<br />";
}
 
?>