Ignore:
Timestamp:
Nov 20, 2009, 3:17:04 PM (14 years ago)
Author:
nikrou
Message:

Feature 1244 resolved
Replace all mysql functions in core code by ones independant of database engine

Fix small php code synxtax : hash must be accessed with [ ] and not { }.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions.inc.php

    r4265 r4325  
    4545  // columns are 'Field', 'Type'
    4646  $result = pwg_query('desc '.$table);
    47   while ($row = mysql_fetch_assoc($result))
     47  while ($row = pwg_db_fetch_assoc($result))
    4848  {
    4949    // we are only interested in the the field given in parameter for the
     
    6060    }
    6161  }
    62   mysql_free_result($result);
     62  pwg_db_free_result($result);
    6363  return $options;
    6464}
     
    597597}
    598598
    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!=null
    634       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 
    647599function pwg_debug( $string )
    648600{
     
    904856
    905857  return $thumbnail_title;
    906 }
    907 
    908 // my_error returns (or send to standard output) the message concerning the
    909 // 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 pattern
    927  * used here
    928  *
    929  * @param string $query
    930  * @param string $fieldname
    931  * @return array
    932  */
    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;
    944858}
    945859
     
    11221036  WHERE '.$conf['user_fields']['id'].' = '.$conf['webmaster_id'].'
    11231037;';
    1124   list($email) = mysql_fetch_row(pwg_query($query));
     1038  list($email) = pwg_db_fetch_row(pwg_query($query));
    11251039
    11261040  return $email;
     
    11431057  $result = pwg_query($query);
    11441058
    1145   if ((mysql_num_rows($result) == 0) and !empty($condition))
     1059  if ((pwg_db_num_rows($result) == 0) and !empty($condition))
    11461060  {
    11471061    fatal_error('No configuration data');
    11481062  }
    11491063
    1150   while ($row = mysql_fetch_assoc($result))
     1064  while ($row = pwg_db_fetch_assoc($result))
    11511065  {
    11521066    $conf[ $row['param'] ] = isset($row['value']) ? $row['value'] : '';
     
    11931107
    11941108  $result = pwg_query($query);
    1195   while ($row = mysql_fetch_assoc($result))
     1109  while ($row = pwg_db_fetch_assoc($result))
    11961110  {
    11971111    $array[ $row[$keyname] ] = $row[$valuename];
     
    12141128  $array = array();
    12151129  $result = pwg_query($query);
    1216   while ($row = mysql_fetch_assoc($result))
     1130  while ($row = pwg_db_fetch_assoc($result))
    12171131  {
    12181132    $array[ $row[$keyname] ] = $row;
     
    15851499    // Use MySql date in order to standardize all recent "actions/queries"
    15861500    list($cache['get_icon']['sql_recent_date']) =
    1587       mysql_fetch_row(pwg_query('select SUBDATE(
     1501      pwg_db_fetch_row(pwg_query('select SUBDATE(
    15881502      CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)'));
    15891503  }
Note: See TracChangeset for help on using the changeset viewer.