Programming
Define() Constant inside mysql connection string probelm

Question Description

Need help with my Programming question - I’m studying for my class.

Hello All:

I am experiencing some difficulties getting some variables from an included file to my mysql connection. Here is what i have:

file one Called config.inc.php:

[PHP]

session_register("client_id");

$_SESSION['client_id'] = $_SESSION['SESS_ACCT_ID'];// 

$club_id=$_SESSION['client_id'];

ob_start();

include('../../../page_title.php');

ob_end_clean();

include('../../../datalogin.php');

if (!defined('DEFAULT_HOST')) define('DEFAULT_HOST','localhost');

if (!defined('DEFAULT_USER')) define('DEFAULT_USER',$account_user);

if (!defined('DEFAULT_PASS')) define('DEFAULT_PASS',$account_pass);

if (!defined('DEFAULT_DB')) define('DEFAULT_DB',$account_db); 

[/PHP]

the variables inside the define() are from the included datalogin.php.

Now, from my second file:

[PHP]

include('config.inc.php');

$link = @mysql_connect(DEFAULT_HOST, DEFAULT_USER, DEFAULT_PASS);

//var_dump($link);

if (!$link) {

   die('Could not connect: ' . mysql_error());

}

# mysql_query("SET SESSION time_zone = '-0:00';");

#mysql_query("SET NAMES 'utf8'", $link);

$db_selected = mysql_select_db(DEFAULT_DB, $link);

if (!$db_selected) {

   die ("Cannot use database: ".DEFAULT_DB.mysql_error());

}

[/PHP]

I'm unable to pass the variable to both:

[PHP]$link = @mysql_connect(DEFAULT_HOST, DEFAULT_USER, DEFAULT_PASS);[/PHP]

and

[PHP]

$db_selected = mysql_select_db(DEFAULT_DB, $link);

[/PHP]

However, I can echo (or print) to screen of:

DEFAULT_DB

DEFAULT_HOST

DEFAULT_USER

DEFAULT_PASS

Any ideas as to what is happening with the lost of the values in the db connection string


Student has agreed that all tutoring, explanations, and answers provided by the tutor will be used to help in the learning process and in accordance with Studypool's honor code & terms of service.

Final Answer

you are create a new id okay...!

UCLA

Anonymous
Top quality work from this tutor! I’ll be back!

Anonymous
Just what I needed… fantastic!

Anonymous
Use Studypool every time I am stuck with an assignment I need guidance.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4