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 Quote Link to comment 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); ?> Quote Link to comment Share on other sites More sharing options...
superprg Posted April 21, 2007 Author Share Posted April 21, 2007 Same error! Quote Link to comment 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? Quote Link to comment 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>'; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.