Re: [PHP] simple, but missing something?
Jas wrote: Not sure why I am not able to get this to work, but to make my stuff easier to configure for different environments I am trying to re-code some of my stuff to work with options from an array. $cfg['hostname'] = "www.server.com"; // Server domain or ip address $cfg['username'] = "username";// Database user name $cfg['password'] = "password";// Database password $cfg['bugemail'] = "[EMAIL PROTECTED]"; The do something like this: function database_connection() { @mysql_connect($cfg[hostname],$cfg[username],$cfg[password]); @mysql_select_database($cfg[database]); } I think your array isn't in scope here, that's why you can't see the array. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] simple, but missing something?
Jay Blanchard wrote: [snip] $cfg['hostname'] = "www.server.com"; // Server domain or ip address $cfg['username'] = "username";// Database user name $cfg['password'] = "password";// Database password $cfg['bugemail'] = "[EMAIL PROTECTED]"; The do something like this: function database_connection() { @mysql_connect($cfg[hostname],$cfg[username],$cfg[password]); @mysql_select_database($cfg[database]); } [/snip] Why are you not using the single quoted array names? i.e. @mysql_connect($cfg['hostname'],$cfg['username'],$cfg['password']); Have you echo'd each out afterwords to see if they are right? Use mysql_error() to return connection errors so that you know what they are. Yeah I have tried single quoted array names, double-quoted variable names, and the output of the print_r($cfg) displays the variables are present and when I do a mysql_error() and mysql_errno() I get could not connect to database, 1046 errors. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] simple, but missing something?
[snip] $cfg['hostname'] = "www.server.com"; // Server domain or ip address $cfg['username'] = "username";// Database user name $cfg['password'] = "password";// Database password $cfg['bugemail'] = "[EMAIL PROTECTED]"; The do something like this: function database_connection() { @mysql_connect($cfg[hostname],$cfg[username],$cfg[password]); @mysql_select_database($cfg[database]); } [/snip] Why are you not using the single quoted array names? i.e. @mysql_connect($cfg['hostname'],$cfg['username'],$cfg['password']); Have you echo'd each out afterwords to see if they are right? Use mysql_error() to return connection errors so that you know what they are. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] simple, but missing something?
Not sure why I am not able to get this to work, but to make my stuff easier to configure for different environments I am trying to re-code some of my stuff to work with options from an array. $cfg['hostname'] = "www.server.com"; // Server domain or ip address $cfg['username'] = "username";// Database user name $cfg['password'] = "password";// Database password $cfg['bugemail'] = "[EMAIL PROTECTED]"; The do something like this: function database_connection() { @mysql_connect($cfg[hostname],$cfg[username],$cfg[password]); @mysql_select_database($cfg[database]); } Is there something special I have to do to get variables out of an array for use here? I have used $user = "name"; and called stuff like @mysql_connect($name); and it has worked before, I think I am missing something here. TIA Jas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php