Ignore:
Timestamp:
Nov 25, 2009, 8:02:57 PM (14 years ago)
Author:
nikrou
Message:

Feature 1255: modification in sql queries

  • manage random function
  • manage regex syntax
  • manage quote (single instead of double)
  • manage interval
File:
1 edited

Legend:

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

    r4325 r4367  
    3333
    3434//----------------------------------------------------------- generic functions
    35 
    36 /**
    37  * returns an array containing the possible values of an enum field
    38  *
    39  * @param string tablename
    40  * @param string fieldname
    41  */
    42 function get_enums($table, $field)
    43 {
    44   // retrieving the properties of the table. Each line represents a field :
    45   // columns are 'Field', 'Type'
    46   $result = pwg_query('desc '.$table);
    47   while ($row = pwg_db_fetch_assoc($result))
    48   {
    49     // we are only interested in the the field given in parameter for the
    50     // function
    51     if ($row['Field'] == $field)
    52     {
    53       // retrieving possible values of the enum field
    54       // enum('blue','green','black')
    55       $options = explode(',', substr($row['Type'], 5, -1));
    56       foreach ($options as $i => $option)
    57       {
    58         $options[$i] = str_replace("'", '',$option);
    59       }
    60     }
    61   }
    62   pwg_db_free_result($result);
    63   return $options;
    64 }
    65 
    66 // get_boolean transforms a string to a boolean value. If the string is
    67 // "false" (case insensitive), then the boolean value false is returned. In
    68 // any other case, true is returned.
    69 function get_boolean( $string )
    70 {
    71   $boolean = true;
    72   if ( 'false' == strtolower($string) )
    73   {
    74     $boolean = false;
    75   }
    76   return $boolean;
    77 }
    78 
    79 /**
    80  * returns boolean string 'true' or 'false' if the given var is boolean
    81  *
    82  * @param mixed $var
    83  * @return mixed
    84  */
    85 function boolean_to_string($var)
    86 {
    87   if (is_bool($var))
    88   {
    89     return $var ? 'true' : 'false';
    90   }
    91   else
    92   {
    93     return $var;
    94   }
    95 }
    9635
    9736// The function get_moment returns a float value coresponding to the number
     
    541480  VALUES
    542481  (
    543     CURDATE(),
    544     CURTIME(),
     482    CURRENT_DATE,
     483    CURRENT_TIME,
    545484    '.$user['id'].',
    546485    \''.$_SERVER['REMOTE_ADDR'].'\',
     
    14981437  {
    14991438    // Use MySql date in order to standardize all recent "actions/queries"
    1500     list($cache['get_icon']['sql_recent_date']) =
    1501       pwg_db_fetch_row(pwg_query('select SUBDATE(
    1502       CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)'));
     1439    $cache['get_icon']['sql_recent_date'] = pwg_db_get_recent_period($user['recent_period']);
    15031440  }
    15041441
Note: See TracChangeset for help on using the changeset viewer.