Re: Opinion about the using $GLOBALS directly
| From: | Sancar Saran | Date: | Fri, 21 Dec 2007 23:23:53 +0000 |
| Subject: | Re: Opinion about the using $GLOBALS directly | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-266221@lists.php.net to get a copy of this message | ||
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