Re: simple, but missing something?

From: Date: Fri, 26 Mar 2004 22:12:42 +0000
Subject: Re: simple, but missing something?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-181590@lists.php.net to get a copy of this message
So something like this? function database_connection() { global = $cfg['hostname'],$cfg['username'],$cfg['password']; @mysql_connect($cfg['hostname'],$cfg['username'],$cfg['password']); @mysql_select_database($cfg['database']); } Or could I do an entire array like so... function database_connection() { global = $cfg; @mysql_connect($cfg['hostname'],$cfg['username'],$cfg['password']); @mysql_select_database($cfg['database']); } ??? Stupid question I know... Geir Pedersen - Activio As wrote:
$cfg['hostname'] = "www.server.com"; // Server domain or ip address
$cfg['username'] = "username";        // Database user name
$cfg['password'] = "password";        // Database password
$cfg['bugemail'] = "admin@server.com"; Then do something like this: function database_connection() { @mysql_connect($cfg[hostname],$cfg[username],$cfg[password]); @mysql_select_database($cfg[database]); }
1) You have to declare $cfg as a global variable in your data_connection() function. PHP differs from C with respect to how you access global variables from within functions. Read about global variables here http://www.php.net/manual/en/language.variables.scope.php 2) Make sure you always quote string constants, even when used as array indexes. --- Geir Pedersen http://www.activio.com/


« previous php.general (#181590) next »