[prev in list] [next in list] [prev in thread] [next in thread] 

List:       twig
Subject:    Re[2]: [twig] multiple connection -> optimization
From:       Emmanuel FAIVRE <manu () manucorp ! com>
Date:       2000-08-18 16:24:42
[Download RAW message or body]

GR>     You should get one connection per pref table used per page load, you
GR> should not get mutiple connections from the same page load to the same table.

GR>                                        Greg

Function GetPref( $pref, $preftable = "", $default = "" )
 {
   global $login, $dbconfig, $userprefs;
                
   TWIGDebug( "GetPref( \"" . $pref . "\", \"" . $preftable . "\", \"" . $default . \
"\" );", 20 );  if( !$preftable ) { $preftable = $dbconfig["prefs_table"]; }

   if( $userprefs[$preftable]["TWIGPrefsLoaded"] != 1 )
   {
         $query = "SELECT * FROM " . $preftable . " WHERE username='" . \
$login["username"] . "'";  $result = dbQuery( $query );
                                
         if( dbNumRows($result) > 0 )
         {
             $userprefs[$preftable] = dbResultArray($result,0);
             $userprefs[$preftable]["TWIGPrefsLoaded"] = 1;
         }
         else
         {
           $userprefs[$preftable][$pref] = $default;
         }
      }
        
   return TWIGProcessSQLString( $userprefs[$preftable][$pref] );
   }


_________________

watch this function if the user does not have a custom config
each time you made a GetPref there is a SQL Query (language menu
submenu....)

Function GetPref( $pref, $preftable = "", $default = "" )
                {
                  global $login, $dbconfig, $userprefs;
                  if (isset($userprefs[$preftable][$pref])) return;


                TWIGDebug( "GetPref( \"" . $pref . "\", \"" . $preftable . "\", \"" . \
$default . "\" );", 20 );

                if( !$preftable ) { $preftable = $dbconfig["prefs_table"]; }
                if($userprefs[$preftable]["TWIGPrefsLoaded"]!=1)
                {
                    $query = "SELECT * FROM " . $preftable . " WHERE username='" . \
$login["username"] . "'";  $result = dbQuery( $query );
                    if( dbNumRows($result) > 0 )
                    {
                        $userprefs[$preftable] = dbResultArray($result,0);
                    }
                    else
                    {
                       $userprefs[$preftable][$pref] = $default;
                    }
                    $userprefs[$preftable]["TWIGPrefsLoaded"] = 1;
                }
                elseif (!isset($userprefs[$preftable][$pref]))
                {
                    $userprefs[$preftable][$pref] = $default;
                }


                return TWIGProcessSQLString( $userprefs[$preftable][$pref] );
                 }
__________________________________________________________________________________

when i made a SQL Query i mark if result is true or false
so i'm sure i only do once
if i get an other variable in the same table just after

i return

if (isset($userprefs[$preftable][$pref])) return;

and if i read the table once and the variable is not set i put default

$userprefs[$preftable][$pref] = $default;


it works fine !

Manu


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic