DarkSuperHero Posted January 6, 2009 Share Posted January 6, 2009 Would it be best to define any MySQL information in a CONSTANT or a variable ? Does it make much of a difference ? <?php define('HOST','localhost'); define('USER','root'); define('PASSWORD',''); define('DATABASE','test'); //OR..... $host = 'localhost'; $user = 'root'; $password = ''; database = 'test'; by the way this is running on a local environment at the moment, but will be running on a production server in the future.... Link to comment https://forums.phpfreaks.com/topic/139696-solved-sql-login-information/ Share on other sites More sharing options...
cytech Posted January 6, 2009 Share Posted January 6, 2009 I would be curious to see if there is any security difference. Link to comment https://forums.phpfreaks.com/topic/139696-solved-sql-login-information/#findComment-730909 Share on other sites More sharing options...
hobeau Posted January 6, 2009 Share Posted January 6, 2009 The fastest most efficient way to do this is to do this as a class constant: <?php class db { Const db_host = "localhost"; Const db_username = "username"; Const db_password = "password"; } ?> PHP handles class constants much better than global constants. To use this simply include the file and say: <?php mysql_connect(db::db_host, db::db_username, db::db_password) or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/139696-solved-sql-login-information/#findComment-730913 Share on other sites More sharing options...
gevans Posted January 6, 2009 Share Posted January 6, 2009 Unless your worried about overwriting data using a standard variable is fine, Apart from that neither will perform any differently. I use an array to hold all my config data like this $CONFIG = array( host => 'localhost' user => 'root' pass => '' database => 'test' ); It's just down to preference Link to comment https://forums.phpfreaks.com/topic/139696-solved-sql-login-information/#findComment-730920 Share on other sites More sharing options...
DarkSuperHero Posted January 6, 2009 Author Share Posted January 6, 2009 oh ok...sweet...ill probably end up using a class constant... :-) i also just finished reading first 3 tutorials on OO PHP here on php freaks and its been enlightening! :-) thanx for the input! :-) Link to comment https://forums.phpfreaks.com/topic/139696-solved-sql-login-information/#findComment-730924 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.