Re: simple, but missing something?

From: Date: Fri, 26 Mar 2004 22:05:20 +0000
Subject: Re: simple, but missing something?
Groups: php.general 
Request: Send a blank email to php-general+get-181589@lists.php.net to get a copy of this message
> $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 (#181589) next »