evanct Posted June 25, 2009 Share Posted June 25, 2009 I have some constants defined here in config.php: define('SQL_HOST','localhost'); define('SQL_USER','root'); define('SQL_PASS','a'); define('SQL_DATABASE','fileservice'); and I try to use them here: require_once('config.php'); $connection=mysql_connect(SQL_HOST,SQL_USER,SQL_PASS); mysql_select_db(SQL_DATABASE,$connection); All I get is some "Use of undefined constants" notices. the require_once link is correct and there's nothing wrong with config.php - it's just a bunch of constant definitions between php tags. This has happened before, I just ended up declaring the mysql_connect variables in the mysql connection script. Quote Link to comment https://forums.phpfreaks.com/topic/163597-solved-constants-not-getting-read/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 25, 2009 Share Posted June 25, 2009 Show us the opening <?php tags that are in config.php Quote Link to comment https://forums.phpfreaks.com/topic/163597-solved-constants-not-getting-read/#findComment-863204 Share on other sites More sharing options...
flyhoney Posted June 25, 2009 Share Posted June 25, 2009 I just set up a test locally and it works fine. Perhaps you should try die()ing in config.php to make sure it is getting included correctly. Quote Link to comment https://forums.phpfreaks.com/topic/163597-solved-constants-not-getting-read/#findComment-863205 Share on other sites More sharing options...
evanct Posted June 25, 2009 Author Share Posted June 25, 2009 nevermind, turns out the require_once link had to be relative to the script that included the connection script, not to the connection script itself Quote Link to comment https://forums.phpfreaks.com/topic/163597-solved-constants-not-getting-read/#findComment-863206 Share on other sites More sharing options...
evanct Posted June 25, 2009 Author Share Posted June 25, 2009 That's really counter-intuitive by the way. if x.php and y.php both include z.php, which includes a.php, shouldn't the link to a.php be relative to z.php? When it's relative to x.php and y.php, and x.php is in a different directory level than y.php, that creates a problem. How do i even work around that? Quote Link to comment https://forums.phpfreaks.com/topic/163597-solved-constants-not-getting-read/#findComment-863210 Share on other sites More sharing options...
PFMaBiSmAd Posted June 25, 2009 Share Posted June 25, 2009 Use absolute file paths, formed by - $_SERVER['DOCUMENT_ROOT'] . '/actual_path/your_file.php' Quote Link to comment https://forums.phpfreaks.com/topic/163597-solved-constants-not-getting-read/#findComment-863211 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.