I have the following php code :
$db_host = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "photos";
define(DB_SERVER,$db_host);
define(DB_USER,$db_user);
define(DB_PASS,$db_pass);
define(DB_NAME,$db_name);
I am defining DB_SERVER and all the other ones as you can see above, but for some reason I get the following errors :
Notice: Use of undefined constant DB_SERVER - assumed 'DB_SERVER' in /Users/ahoura/Sites/photos/include/config.php on line 34 Notice: Use of undefined constant DB_USER - assumed 'DB_USER' in /Users/ahoura/Sites/photos/include/config.php on line 35 Notice: Use of undefined constant DB_PASS - assumed 'DB_PASS' in /Users/ahoura/Sites/photos/include/config.php on line 36 Notice: Use of undefined constant DB_NAME - assumed 'DB_NAME' in /Users/ahoura/Sites/photos/include/config.php on line 37
What am I doing wrong!?!?!
You need to quote the names of your new constants in
define()The notice indicates that PHP did in fact treat them as quoted strings because it could not locate existing constants with those names, but this is bad practice to rely on.
define()takes a string as the name of the constant to be defined, and its intended value.