开发者

php define constant - scope of use?

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开发者_如何学JAVA 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?


Not wanting the answer to be too long:

Yes.


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().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜