Warning: Invalid argument supplied for foreach() in /home/jihswbiz/public_html/t6.gwilt.org/refDox.php on line 212
Docs-serverLoad

 

ReLoad

Keys


Functions

arraybrowsercolorcookiedatetimeDBdebugdeviceDSTequiverrorflagsfontformatgeo
holidayhtmlisjsonmathparsePHPprintsearchsortstringtabletexttracetype
VOTDweatherxml

Function  serverLoad   Lines 24-166 (142 lines) file  utilsServerDB Geo.php   Last mod: Tue 2021-04-06 21:05:14

function serverLoad ()
        {
#-k     DB      geo
#-      $sq['init']     = 0: 1 or more tables are missing
#-                      = 1: all tables exist & OK
        
global $sq;

        
$raw debug_backtrace();
        
$sq['f'] = $raw[0]['function'];
        
$sq['e'] = err_ok;
        
$sq['err'] = '';
        if (
$sq['init'] > 0) return $sq;        # Already connected to SQL server

#       Do the tables exist?
        
$sq['dbot']++;
        
$conn mysqli_connect $sq['s'], $sq['u'], $sq['p'], $sq['d'] );
        
$sq['conn'] = $conn;
        
$sq['dbot']++;
        
$err mysqli_error($conn);
        if (
strlen($err)) { $sq['err'] = $err$sq['e'] = 101; return $sq; }

        
$q 'SHOW TABLES FROM ' $sq['d'];
        
$sq['dbot']++;
        
$sq['q'] = $q;
        
$qres mysqli_query $conn$q );
        
$sq['dbot']++;
        
$err mysqli_error($conn);
        if (
strlen($err)) { $sq['err'] = $err$sq['e'] = 103; return $sq; }

        
$country false;
        
$tzone   false;
        
$zipcode false;

        while (
$row mysqli_fetch_array($qres,MYSQLI_BOTH))
                {
                if (
$row[0] == "cntry")   $country true;
                if (
$row[0] == "tzone")   $tzone   true;
                if (
$row[0] == "zipcode"$zipcode true;
                }

        if (
$country  and  $tzone  and  $zipcode)
                {
                
$sq['init'] = 2;        # ready to run
                
return $sq;
                }
                
#       One or more tables need to be created
        
if (!$zipcode)
                {       
# need to create the table
prt "Creating 'zipload'" );
                
$sq['err'] = '';
        
##      zipcode:
#               zip     VARCHAR(10)
#               cc      CHAR(2)
#               city    VARCHAR(40)
#               st      VARCHAR(40)
#               lat     VARCHAR(12)
#               lon     VARCHAR(12)
#               tz      VARCHAR(40)
#               DST     VARCHAR(7)
##

        
$q 'CREATE TABLE zipcode (
                zip     VARCHAR(10),
                cc      CHAR(2),
                city    VARCHAR(40),
                st      VARCHAR(40),
                lat     VARCHAR(12),
                lon     VARCHAR(12),
                tz      VARCHAR(40),
                DST     VARCHAR(7),
                PRIMARY KEY (zip, cc) )'
;

                
$sq['dbot']++;
                
$sq['q'] = $q;
                
$qres mysqli_query $conn$q );
                
$sq['dbot']++;
                
$err mysqli_error($conn);
                if (
strlen($err)) { $sq['err'] = $err$sq['e'] = 104prt($q); return $sq; }
                
prt 'Created [zipcode]<br>' );
                }       

        if (!
$country)
                {       
# need to create the table
prt "'Creating 'cntry'" );
                
$sq['err'] = '';
        
##      cntry:
#               cc      CHAR(2)
#               country VARCHAR(30)
##

        
$q 'CREATE TABLE cntry (
                cc      CHAR(2),
                country VARCHAR(30),
                PRIMARY KEY (cc) )'
;

                
$sq['q'] = $q;
                
$qres mysqli_query $conn$q );
                
$sq['dbot']++;
                
$err mysqli_error($conn);
                if (
strlen($err)) { $sq['err'] = $err$sq['e'] = 104prt($q); return $sq; }
                
prt 'Created [cntry]<br>' );
                }       

        if (!
$tzone)
                {       
# need to create the table
prt "'Creating 'tzone'" );
                
$sq['err'] = '';
        
##      tzone:
#               tz              VARCHAR(90)
#               cc              CHAR(2)
#               lat             VARCHAR(12)
#               long            VARCHAR(12)
#               standard        VARCHAR(7)
#               summer          VARCHAR(7)
#               comments        VARCHAR(90)
##

        
$q 'CREATE TABLE tzone (
                tz              VARCHAR(90),
                cc              CHAR(2),
                lat             VARCHAR(12),
                lon             VARCHAR(12),
                standard        VARCHAR(7),
                summer          VARCHAR(7),
                comments        VARCHAR(90),
                PRIMARY KEY (tz) )'
;

                
$sq['q'] = $q;
                
$qres mysqli_query $conn$q );
                
$sq['dbot']++;
                
$err mysqli_error($conn);
                if (
strlen($err)) { $sq['err'] = $err$sq['e'] = 104prt($q); return $sq; }
                
prt 'Created [tzone]<br>' );
                }       

        
$sq['init'] = 1;        # ready to run
        
return $sq;
        }

?>