NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Using variables in PHP

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 03-02-2007, 07:17 PM THREAD STARTER               #1 (permalink)
NamePros Regular
Join Date: Jan 2006
Posts: 733
gericsb is an unknown quantity at this point
 



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)
gericsb is offline  
Old 03-02-2007, 08:58 PM   #2 (permalink)
NamePros Regular
Join Date: Feb 2006
Posts: 528
psalzmann is just really nicepsalzmann is just really nicepsalzmann is just really nicepsalzmann is just really nice
 



Originally Posted by gericsb
<?php
????: NamePros.com http://www.namepros.com/showthread.php?t=300518
require_once('global.php');
$dbh=mysql_connect('DBHOST', 'DBUSER', 'DBPASS') or die ('I cannot connect to the database because: ' . mysql_error());
etc...........
?>
Is your problem. You need to remove the single quotes if they are CONSTANTS.

Use this:
PHP Code:
<?php
require_once('global.php');
$dbh=mysql_connect(DBHOSTDBUSERDBPASS) or die ('I cannot connect to the database because: ' mysql_error());
etc...........
?>
psalzmann is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 12:05 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger