| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Regular Join Date: Jan 2006
Posts: 733
![]() | 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. ????: NamePros.com http://www.namepros.com/programming/300518-using-variables-in-php.html Thanks anyway!
__________________ Online Dating Personals Affiliate Marketing Blog Invite.tv Geometry.tv Texting.tv Remedial.tv Firearms.tv Pulpit.tv Pumping.tv Personales.tv (Personals) Bancos.tv (Banks) Zapatos.tv (Shoes) |
| |
| | #2 (permalink) | ||||
| NamePros Regular Join Date: Feb 2006
Posts: 528
![]() ![]() ![]() ![]() |
Use this: PHP Code: | ||||
| |