superprg Posted April 21, 2007 Share Posted April 21, 2007 Hi this is db.php <? define('DB_SERVER','localhost'); define('DB_SERVER_USERNAME','root'); define('DB_SERVER_PASSWORD','root'); define('DB_DATABASE','osc'); ?> and this is index.php <?php include("db.php"); tep_db_connect() or die('Unable to connect to database server!'); function tep_db_connect($server = DB_SERVER, $username = DB_SERVER_USERNAME, $password = DB_SERVER_PASSWORD, $database = DB_DATABASE, $link = 'db_link') { global $$link; if (USE_PCONNECT == 'true') { $$link = mysql_pconnect($server, $username, $password); } else { $$link = mysql_connect($server, $username, $password); } if ($$link) mysql_select_db($database); return $$link; } ?> I am getting errors like Use of undefined constant DB_SERVER - assumed 'DB_SERVER' in C:\Program Files\Apache Group\Apache2\htdocs\php_test\$$test.php on line 14 Can someone tell me why it is not able to recognize the variables Also, whats the significance of the $$link Is that a special variabel in php? Why cant we simply use $link? Thanks Link to comment https://forums.phpfreaks.com/topic/48039-define-not-working-in-include/ Share on other sites More sharing options...
Lumio Posted April 21, 2007 Share Posted April 21, 2007 what are you trying to do? hm... try that: <?php require_once 'db.php'; $dbc = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD); if ($dbc) mysql_select_db(DB_DATABASE); ?> Link to comment https://forums.phpfreaks.com/topic/48039-define-not-working-in-include/#findComment-234830 Share on other sites More sharing options...
superprg Posted April 21, 2007 Author Share Posted April 21, 2007 Same error! Link to comment https://forums.phpfreaks.com/topic/48039-define-not-working-in-include/#findComment-234835 Share on other sites More sharing options...
superprg Posted April 22, 2007 Author Share Posted April 22, 2007 Ok it works when I use <?php and not <? Anyways, can someone tell me what are $$var in php? Link to comment https://forums.phpfreaks.com/topic/48039-define-not-working-in-include/#findComment-235078 Share on other sites More sharing options...
Lumio Posted April 22, 2007 Share Posted April 22, 2007 Ok... we say you define a variable like this: <?php $var = 'foo'; ?> Okay! Now we say, we want to define a variable and name it as the value of $var. Thats what the second $ does: <?php $var = 'foo'; $$var = 'bar'; ?> Now lets see what the following variables contains: <?php $var = 'foo'; $$var = 'bar'; echo $var.'<br>'; echo $$var.'<br>'; echo $foo.'<br>'; ?> Link to comment https://forums.phpfreaks.com/topic/48039-define-not-working-in-include/#findComment-235386 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.