Jump to content

Define not working in include


superprg

Recommended Posts

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

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>';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.