0

Not wanting this question to be too long, I will skip to an example:
If I have 2 files: paper.php and rock.php, and they contain the following:

paper.php:

include('rock.php');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
$db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");

and rock.php:

define ("DB_HOST", "localhost");
define ("DB_USER", "foo");
define ("DB_PASS","bar");
define ("DB_NAME","fooDBar");

Eventually, will the user viewing my paper.php file be connected to the DB or not?

3
  • 1
    It should work as you've coded. Commented Jul 5, 2011 at 21:05
  • 2
    a DIY test-approach would have been much quicker than posting it here, by the way :) Yup, i often use an include-file with tons of constants like in your example, works like a charm Commented Jul 5, 2011 at 21:12
  • thanks everyone! a test would have been faster of course,but my server has some issues right now so yeah... i posted here. Thanks again! Commented Jul 6, 2011 at 12:10

2 Answers 2

12

Not wanting the answer to be too long:

Yes.

Sign up to request clarification or add additional context in comments.

Comments

7

Yes, you define all the appropriate variables in rock.php and are including rock.php, then they will be defined for the whole program execution, including where you do a mysql_connect().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.