Changeset 1509 in ExiteCMS for branches/PLi-Fusion/includes/db_functions.php
- Timestamp:
- 07/02/08 18:27:06 (4 years ago)
- File:
-
- 1 edited
-
branches/PLi-Fusion/includes/db_functions.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/PLi-Fusion/includes/db_functions.php
r1408 r1509 24 24 // database global variables 25 25 $_db_debug = false; 26 $_db_log = false;26 $_db_log = true; 27 27 $_db_logs = array(); 28 28 $_db_last_function = ""; … … 53 53 54 54 // MySQL database functions 55 function dbquery($query, $display= true) {56 57 global $_db_last_function, $_db_debug, $_db_log, $_db_logs, $_loadstats ;55 function dbquery($query, $display=false) { 56 57 global $_db_last_function, $_db_debug, $_db_log, $_db_logs, $_loadstats, $settings; 58 58 59 59 // update the query for relocated user tables 60 60 ModUserTables($query); 61 62 $_s_loadtime = explode(" ", microtime());63 $_s_loadtime = $_s_loadtime[1] + $_s_loadtime[0];64 $_loadstats['querytime'] -= $_s_loadtime;65 61 66 62 if ($_db_debug) { … … 87 83 } 88 84 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 90 95 if (!$result) { 91 if ($display ) {96 if ($display || $settings['debug_querylog']) { 92 97 echo "<pre><br />Query: ".$query."<br />"; 93 98 echo mysql_error(); 94 99 echo "</pre>"; 95 100 } 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 } 101 103 102 104 if ($_db_log) { … … 107 109 } 108 110 111 // DEPRECIATED. Function is replaced by the more generic dbfunction(), and will be removed in a later release of ExiteCMS 109 112 function 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 118 function dbfunction($field,$table,$conditions="") { 119 global $db_prefix, $_db_last_function, $_db_debug, $_db_log, $_db_logs, $settings; 111 120 112 121 $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; 114 123 115 124 $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 125 130 function 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 136 135 function dbrows($resource) { 137 136 global $_db_last_function, $_db_debug; … … 154 153 } 155 154 155 // return a assoc array of the current row 156 156 function dbarray($resource) { 157 global $settings; 158 157 159 $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 166 164 function dbarraynum($resource) { 165 global $settings; 166 167 167 $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) 176 172 function dbtable_exists($tbl, $db='') { 177 173 global $db_name; … … 197 193 $_loadstats['queries']++; 198 194 $_loadstats['others']++; 199 $_db_last_function = "SHOW TABLES";200 195 $_e_loadtime = explode(" ", microtime()); 201 196 $_e_loadtime = $_e_loadtime[1] + $_e_loadtime[0]; 202 197 $_loadstats['querytime'] += $_e_loadtime; 203 198 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); 205 200 } 206 201 … … 212 207 } 213 208 214 209 // connect to the database engine and select the database 215 210 function dbconnect($db_host, $db_user, $db_pass, $db_name) { 216 211 $db_connect = @mysql_connect($db_host, $db_user, $db_pass, true); 217 $db_select = @mysql_select_db($db_name);218 212 if (!$db_connect) { 219 213 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 } 222 219 } 223 220 return $db_connect; 224 221 } 225 222 226 // convert MySQL date to a formatted date ( use subheaderdate setting) by WanWizard227 function showMySQLdate($date, $empty="", $error="" ) {223 // convert MySQL date to a formatted date (default format is subheaderdate) 224 function showMySQLdate($date, $empty="", $error="", $format="subheaderdate") { 228 225 global $locale, $settings; 229 226 … … 237 234 $year=substr($date,0,4); $month=substr($date,5,2); $day=substr($date,8,2); 238 235 $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))); 240 237 } 241 238
Note: See TracChangeset
for help on using the changeset viewer.
