Re: Is "Function Constants" the Correct Term?

From: Date: Sun, 18 Jul 2004 09:44:21 +0000
Subject: Re: Is "Function Constants" the Correct Term?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-190890@lists.php.net to get a copy of this message
<pre> <? define(LOGIN,"user"); define(PASS,"pass"); define(DB,"mysql");
function dblogin($login,$pass,$db) {
    $mysql = mysql_connect("localhost",$login,$pass);
    mysql_select_db($db,$mysql);
} ?> </pre>
If you're trying to protect your login credentials, you could create a class for performing mysql actions. Then put the credentials into private/protected members or constants. <?php // This is an example. Using protected members instead of constants would be // more flexible (you can extend the class with wrappers for each database). class MySQL { const HOST = 'your_DSN'; const USER = 'Monty_Python'; const PASS = 'Your_father_was_a_hamster_and_your_mother_smelled_of_elderberries'; function __construct() {
    $this->connect();
} function connect () {
    mysql_connect(self::HOST, self::USER, self::PASS);
} // query methods, etc. } ?>

« previous php.general (#190890) next »