Changeset 4325 for trunk/include/functions.inc.php
- Timestamp:
- Nov 20, 2009, 3:17:04 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions.inc.php
r4265 r4325 45 45 // columns are 'Field', 'Type' 46 46 $result = pwg_query('desc '.$table); 47 while ($row = mysql_fetch_assoc($result))47 while ($row = pwg_db_fetch_assoc($result)) 48 48 { 49 49 // we are only interested in the the field given in parameter for the … … 60 60 } 61 61 } 62 mysql_free_result($result);62 pwg_db_free_result($result); 63 63 return $options; 64 64 } … … 597 597 } 598 598 599 function pwg_query($query)600 {601 global $conf,$page,$debug,$t2;602 603 $start = get_moment();604 ($result = mysql_query($query)) or my_error($query, $conf['die_on_sql_error']);605 606 $time = get_moment() - $start;607 608 if (!isset($page['count_queries']))609 {610 $page['count_queries'] = 0;611 $page['queries_time'] = 0;612 }613 614 $page['count_queries']++;615 $page['queries_time']+= $time;616 617 if ($conf['show_queries'])618 {619 $output = '';620 $output.= '<pre>['.$page['count_queries'].'] ';621 $output.= "\n".$query;622 $output.= "\n".'(this query time : ';623 $output.= '<b>'.number_format($time, 3, '.', ' ').' s)</b>';624 $output.= "\n".'(total SQL time : ';625 $output.= number_format($page['queries_time'], 3, '.', ' ').' s)';626 $output.= "\n".'(total time : ';627 $output.= number_format( ($time+$start-$t2), 3, '.', ' ').' s)';628 if ( $result!=null and preg_match('/\s*SELECT\s+/i',$query) )629 {630 $output.= "\n".'(num rows : ';631 $output.= mysql_num_rows($result).' )';632 }633 elseif ( $result!=null634 and preg_match('/\s*INSERT|UPDATE|REPLACE|DELETE\s+/i',$query) )635 {636 $output.= "\n".'(affected rows : ';637 $output.= mysql_affected_rows().' )';638 }639 $output.= "</pre>\n";640 641 $debug .= $output;642 }643 644 return $result;645 }646 647 599 function pwg_debug( $string ) 648 600 { … … 904 856 905 857 return $thumbnail_title; 906 }907 908 // my_error returns (or send to standard output) the message concerning the909 // error occured for the last mysql query.910 function my_error($header, $die)911 {912 $error = "[mysql error ".mysql_errno().'] '.mysql_error()."\n";913 $error .= $header;914 915 if ($die)916 {917 fatal_error($error);918 }919 echo("<pre>");920 trigger_error($error, E_USER_WARNING);921 echo("</pre>");922 }923 924 925 /**926 * creates an array based on a query, this function is a very common pattern927 * used here928 *929 * @param string $query930 * @param string $fieldname931 * @return array932 */933 function array_from_query($query, $fieldname)934 {935 $array = array();936 937 $result = pwg_query($query);938 while ($row = mysql_fetch_assoc($result))939 {940 array_push($array, $row[$fieldname]);941 }942 943 return $array;944 858 } 945 859 … … 1122 1036 WHERE '.$conf['user_fields']['id'].' = '.$conf['webmaster_id'].' 1123 1037 ;'; 1124 list($email) = mysql_fetch_row(pwg_query($query));1038 list($email) = pwg_db_fetch_row(pwg_query($query)); 1125 1039 1126 1040 return $email; … … 1143 1057 $result = pwg_query($query); 1144 1058 1145 if (( mysql_num_rows($result) == 0) and !empty($condition))1059 if ((pwg_db_num_rows($result) == 0) and !empty($condition)) 1146 1060 { 1147 1061 fatal_error('No configuration data'); 1148 1062 } 1149 1063 1150 while ($row = mysql_fetch_assoc($result))1064 while ($row = pwg_db_fetch_assoc($result)) 1151 1065 { 1152 1066 $conf[ $row['param'] ] = isset($row['value']) ? $row['value'] : ''; … … 1193 1107 1194 1108 $result = pwg_query($query); 1195 while ($row = mysql_fetch_assoc($result))1109 while ($row = pwg_db_fetch_assoc($result)) 1196 1110 { 1197 1111 $array[ $row[$keyname] ] = $row[$valuename]; … … 1214 1128 $array = array(); 1215 1129 $result = pwg_query($query); 1216 while ($row = mysql_fetch_assoc($result))1130 while ($row = pwg_db_fetch_assoc($result)) 1217 1131 { 1218 1132 $array[ $row[$keyname] ] = $row; … … 1585 1499 // Use MySql date in order to standardize all recent "actions/queries" 1586 1500 list($cache['get_icon']['sql_recent_date']) = 1587 mysql_fetch_row(pwg_query('select SUBDATE(1501 pwg_db_fetch_row(pwg_query('select SUBDATE( 1588 1502 CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)')); 1589 1503 }
Note: See TracChangeset
for help on using the changeset viewer.