PHP How to access constant defined outside class?

Posted by Ashley Ward on Stack Overflow See other posts from Stack Overflow or by Ashley Ward
Published on 2010-06-11T15:10:03Z Indexed on 2010/06/11 15:12 UTC
Read the original article Hit count: 229

Filed under:
|
|
|
|

I have defined some constants eg:

define('DB_HOSTNAME', 'localhost', true);
define('DB_USERNAME', 'root', true);
define('DB_PASSWORD', 'root', true);
define('DB_DATABASE', 'authtest', true);

now when I try to do this:

class Auth{
function AuthClass() {
$this->db_link = mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD) 
or die(mysql_error());
}
}

I get an error. Why is this and what do I need to do?

See, I've tried using (for example) global DB_HOSTNAME but this fails with an error.

© Stack Overflow or respective owner

Related posts about php

Related posts about class