Ignore:
Timestamp:
07/02/08 18:27:06 (4 years ago)
Author:
hverton
Message:

Merged trunk revisions 1408:1508 into the PLi-Fusion branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PLi-Fusion/includes/db_functions.php

    r1408 r1509  
    2424// database global variables 
    2525$_db_debug = false; 
    26 $_db_log = false; 
     26$_db_log = true; 
    2727$_db_logs = array(); 
    2828$_db_last_function = ""; 
     
    5353 
    5454// MySQL database functions 
    55 function dbquery($query, $display=true) { 
    56  
    57     global $_db_last_function, $_db_debug, $_db_log, $_db_logs, $_loadstats; 
     55function dbquery($query, $display=false) { 
     56 
     57    global $_db_last_function, $_db_debug, $_db_log, $_db_logs, $_loadstats, $settings; 
    5858 
    5959    // update the query for relocated user tables 
    6060    ModUserTables($query); 
    61  
    62     $_s_loadtime = explode(" ", microtime()); 
    63     $_s_loadtime = $_s_loadtime[1] + $_s_loadtime[0]; 
    64     $_loadstats['querytime'] -= $_s_loadtime; 
    6561 
    6662    if ($_db_debug) { 
     
    8783    } 
    8884 
    89     $result = @mysql_query($query); 
     85    $_s_loadtime = explode(" ", microtime()); 
     86    $_s_loadtime = (float)$_s_loadtime[1] + (float)$_s_loadtime[0]; 
     87 
     88    $result = mysql_query($query); 
     89 
     90    $_e_loadtime = explode(" ", microtime()); 
     91    $_e_loadtime = (float)$_e_loadtime[1] + (float)$_e_loadtime[0]; 
     92 
     93    $_loadstats['querytime'] = $_loadstats['querytime'] + $_e_loadtime - $_s_loadtime; 
     94 
    9095    if (!$result) { 
    91         if ($display) { 
     96        if ($display || $settings['debug_querylog']) { 
    9297            echo "<pre><br />Query: ".$query."<br />"; 
    9398            echo mysql_error(); 
    9499            echo "</pre>"; 
    95100        } 
    96         trigger_error(mysql_error(), E_USER_ERROR); 
    97     } 
    98     $_e_loadtime = explode(" ", microtime()); 
    99     $_e_loadtime = $_e_loadtime[1] + $_e_loadtime[0]; 
    100     $_loadstats['querytime'] += $_e_loadtime; 
     101        trigger_error("A MySQL error has been detected that is not recoverable:", E_USER_ERROR); 
     102    } 
    101103 
    102104    if ($_db_log) { 
     
    107109} 
    108110 
     111// DEPRECIATED. Function is replaced by the more generic dbfunction(), and will be removed in a later release of ExiteCMS 
    109112function dbcount($field,$table,$conditions="") { 
    110     global $db_prefix, $_db_last_function, $_db_debug, $_db_log, $_db_logs; 
     113 
     114    return dbfunction("COUNT".$field, $table, $conditions); 
     115} 
     116 
     117// perform a function on a table (COUNT, MAX, MIN, etc) and return the value, based on the field and conditions specified 
     118function dbfunction($field,$table,$conditions="") { 
     119    global $db_prefix, $_db_last_function, $_db_debug, $_db_log, $_db_logs, $settings; 
    111120 
    112121    $cond = ($conditions ? " WHERE ".$conditions : ""); 
    113     $sql = "SELECT Count".$field." FROM ".(strpos($table, ".") ? $table : $db_prefix.$table).$cond; 
     122    $sql = "SELECT ".$field." FROM ".(strpos($table, ".") ? $table : $db_prefix.$table).$cond; 
    114123 
    115124    $result = dbquery($sql, false); 
    116     if (!$result) { 
    117         echo mysql_error(); 
    118         return false; 
    119     } else { 
    120         $rows = mysql_result($result, 0); 
    121         return $rows; 
    122     } 
    123 } 
    124  
     125    $rows = mysql_result($result, 0); 
     126    return $rows; 
     127} 
     128 
     129// DEPRECIATED. Function definition left here to capture code that needs to be modified 
    125130function dbresult($resource, $row) { 
    126  
    127     $result = @mysql_result($resource, $row); 
    128     if (!$result) { 
    129         echo mysql_error(); 
    130         return false; 
    131     } else { 
    132         return $result; 
    133     } 
    134 } 
    135  
     131    die("ExiteCMS: The function 'dbresult' is depreciated starting version 7.2. Please rewrite your code using dbfunction()!"); 
     132} 
     133 
     134// return the number of rows affected in the most recent query 
    136135function dbrows($resource) { 
    137136    global $_db_last_function, $_db_debug; 
     
    154153} 
    155154 
     155// return a assoc array of the current row 
    156156function dbarray($resource) { 
     157    global $settings; 
     158 
    157159    $result = @mysql_fetch_assoc($resource); 
    158     if (!$result) { 
    159         echo mysql_error(); 
    160         return false; 
    161     } else { 
    162         return $result; 
    163     } 
    164 } 
    165  
     160    return $result; 
     161} 
     162 
     163// return a numbered array of the current row 
    166164function dbarraynum($resource) { 
     165    global $settings; 
     166 
    167167    $result = @mysql_fetch_row($resource); 
    168     if (!$result) { 
    169         echo mysql_error(); 
    170         return false; 
    171     } else { 
    172         return $result; 
    173     } 
    174 } 
    175  
     168    return $result; 
     169} 
     170 
     171// check if a table exists, optionally passing the name of a database (if empty, use the currently selected database) 
    176172function dbtable_exists($tbl, $db='') { 
    177173    global $db_name; 
     
    197193    $_loadstats['queries']++; 
    198194    $_loadstats['others']++; 
    199     $_db_last_function = "SHOW TABLES"; 
    200195    $_e_loadtime = explode(" ", microtime()); 
    201196    $_e_loadtime = $_e_loadtime[1] + $_e_loadtime[0]; 
    202197    $_loadstats['querytime'] += $_e_loadtime; 
    203198    if ($_db_log) { 
    204         $_db_logs[] = array($_db_last_function, ($_e_loadtime - $_s_loadtime)*1000); 
     199        $_db_logs[] = array("SHOW TABLES", ($_e_loadtime - $_s_loadtime)*1000); 
    205200    } 
    206201 
     
    212207} 
    213208 
    214  
     209// connect to the database engine and select the database 
    215210function dbconnect($db_host, $db_user, $db_pass, $db_name) { 
    216211    $db_connect = @mysql_connect($db_host, $db_user, $db_pass, true); 
    217     $db_select = @mysql_select_db($db_name); 
    218212    if (!$db_connect) { 
    219213        die("<div style='font-family:Verdana;font-size:11px;text-align:center;'><b>Unable to establish connection to MySQL</b><br />".mysql_errno()." : ".mysql_error()."</div>"); 
    220     } elseif (!$db_select) { 
    221         die("<div style='font-family:Verdana;font-size:11px;text-align:center;'><b>Unable to select MySQL database</b><br />".mysql_errno()." : ".mysql_error()."</div>"); 
     214    } else { 
     215        $db_select = @mysql_select_db($db_name); 
     216        if (!$db_select) { 
     217            die("<div style='font-family:Verdana;font-size:11px;text-align:center;'><b>Unable to select MySQL database</b><br />".mysql_errno()." : ".mysql_error()."</div>"); 
     218        } 
    222219    } 
    223220    return $db_connect; 
    224221} 
    225222 
    226 // convert MySQL date to a formatted date (use subheaderdate setting) by WanWizard 
    227 function showMySQLdate($date, $empty="", $error="") { 
     223// convert MySQL date to a formatted date (default format is subheaderdate) 
     224function showMySQLdate($date, $empty="", $error="", $format="subheaderdate") { 
    228225    global $locale, $settings; 
    229226 
     
    237234    $year=substr($date,0,4); $month=substr($date,5,2); $day=substr($date,8,2); 
    238235    $hour=substr($date,11,2); $minute=substr($date,14,2); $second=substr($date,17,2); 
    239     return ucwords(showdate($settings['subheaderdate'], mktime($hour,$minute,$second,$month,$day,$year))); 
     236    return ucwords(showdate((isset($settings[$format])?$settings[$format]:$settings['subheaderdate']), mktime($hour,$minute,$second,$month,$day,$year))); 
    240237} 
    241238 
Note: See TracChangeset for help on using the changeset viewer.