I have 2 files index.php and env.php file. I would like to use the variable from env.php file inside the index.php file for connecting to the DB. I have tried doing this like this:
env.php:
<?php
$dbSettings = ["192.168.10.10", "homestead", "secret", "mydatabase"];
?>
And then requiring the env.file in index.php file and using the $dbSettings variable in index.php file like this:
<?php
error_reporting( E_ALL );
ini_set( 'display_errors', 1 );
require 'env.php';
class Calculator{
var $mysqli;
public function Calculator(){
$this->mysqli = mysqli_connect( $dbSettings );
}
But, I get the error:
Notice: Undefined variable: dbSettings in /home/vagrant/Projects/MyProject/index.php on line 14