Re: Opinion about the using $GLOBALS directly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



example code
// current code

//--- Set DB
$GLOBALS['db'] = NewADOConnection($GLOBALS['c']['db']['type'].'://'. 
$GLOBALS['c']['db']['user'].':'.$GLOBALS['c']['db']['pass'].'@'.$GLOBALS['c']
['db']['host'].'/'.$GLOBALS['c']['db']['name']);
$ADODB_FETCH_MODE = ADODB_FETCH_NUM; // Fastest Get Method


function getGalaxy() {
$sqlGGal = "
SELECT *
  FROM ".$GLOBALS['c']['db']['pref']."universe
 WHERE planet_type     = 'planet'
   AND planet_galaxy   = '1'
   AND planet_owner_id = 'null'
 ORDER BY planet_id ASC";

$GLOBALS['ADODB_FETCH_MODE'] = ADODB_FETCH_ASSOC;
$resGGAL   = $GLOBALS['db']->Execute($sqlGGal);
return $resGal;
}

Other Suggestions

function getGalaxy() {
$dbPrefix = $GLOBALS['c']['db']['pref'];
$db = $GLOBALS['db'];
$sqlGGal = "
SELECT *
  FROM ".$dbPrefix."universe
 WHERE planet_type     = 'planet'
   AND planet_galaxy   = '1'
   AND planet_owner_id = 'null'
 ORDER BY planet_id ASC";

$GLOBALS['ADODB_FETCH_MODE'] = ADODB_FETCH_ASSOC;
$resGGAL   = $db->Execute($sqlGGal);
return $resGal;
}

or

function getGalaxy() {
$dbConfig = Zend_Registry::get('dbConfig');
$dbPrefix = $dbConfig['prefix'];
$db = NewADOConnection($dbConfig['type'].'://'. $dbConfig['user'].':'.
$dbConfig['pass'].'@'.$dbConfig['host'].'/'.$dbConfig['name']);

$sqlGGal = "
SELECT *
  FROM ".$dbPrefix."universe
 WHERE planet_type     = 'planet'
   AND planet_galaxy   = '1'
   AND planet_owner_id = 'null'
 ORDER BY planet_id ASC";

$GLOBALS['ADODB_FETCH_MODE'] = ADODB_FETCH_ASSOC;
$resGGAL   = $db->Execute($sqlGGal);
$db->Close();
return $resGal;
}

Etc etc. 

>From my point of view first one was more usable. 

Anyhow dont worry. It seems PHP 5.3.0 supporting _NAMESPACE_ :)

Regards

Sancar

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux