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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.