0

I have been stuck on this syntax issue for ever now and none of the information I found on anywhere seemed to work.

all I want to do is use a variable, I have about 20-30 files that need to connect to database, changing the credentials on all those pages every time would be such a pain, so im trying to link to a Variable.php file.

this is the code:

    require( "http://domainname/resources/Variable.php" );
$sql_details = array(
    "user" => $DBUsername,
    "pass" => $DBPassword,
    "db"   => $DBName,
    "host" => $DBHost
);

this is how the syntax was before I tried to add variable, which when ran gives me no errors like when I try to use variable

$sql_details = array(
     'user' => 'username',
    'pass' => 'password',
    'db'   => 'database',
    'host' => 'localhost'
);
user3893380
  • 33
  • 1
  • 1
  • 6

2 Answers2

0

I would suggest as below.

require( "Variable.php" ); // Use Absolute path here

$sql_details = array(
    "user" => $DBUsername,
    "pass" => $DBPassword,
    "db"   => $DBName,
    "host" => $DBHost
);

Here you can use global keyword to use another file variable e.g global $DBUsername

bunty007
  • 27
  • 9
0

I ended up listening to the commenters and used the absolute path "var/www/html/directory1/directory2/login.php" and everything works fine now.

user3893380
  • 33
  • 1
  • 1
  • 6