| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| NamePros Regular | Using variables in PHP I have defined the following constants in a file called global.php where I have used my actual database username, password etc.--I just replaced them here so nobody could see them: <?php // Database constants DEFINE('DBUSER', 'mydatabaseusername'); DEFINE('DBPASS', 'mydatabasepassword'); DEFINE('DBHOST', 'localhost'); DEFINE('DB', 'nameofmydatabase'); ?> I then include the global.php file in my test page using the require_once command as seen below: <?php require_once('global.php'); $dbh=mysql_connect('DBHOST', 'DBUSER', 'DBPASS') or die ('I cannot connect to the database because: ' . mysql_error()); etc........... ?> No matter how I include my constants in the connect command above, I cannot connect to my database. Now if I replace the DBHOST with "localhost" and the DBUSER with the actual name of my user etc.--all stuff I defined in the gloabl.php file--everything works fine. But--I must use the actual names in " " and not the constants like above. I made sure my global.php page and my test page were in the same folder so its not a path issue... So why aren't my DEFINE commands working? Figured it out... Couldn't have the single quotes around the DBHOST, DBUSER....etc. Thanks anyway! |
| |
| | #2 (permalink) | |
| NamePros Regular | Quote:
Use this: PHP Code: | |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |