I'm trying to give
require_oncein a PHP file that has a class.
The file I'm trying to include in PHP with the class has only one array with configuration data, but I can not get it properly.
class CoreDatabase { public $database; public function __construct() { require_once('aps/config/database.php'); $this->database = new PDO($db_data['default']['driver'] . ':host=' . $db_data['default']['host'] . ';dbname=' . $db_data['default']['name'], $db_data['default']['user'], $db_data['default']['password']); $statement = $this->database->prepare('select * from tablex'); $statement->execute(); echo var_dump($statement->fetch(PDO::FETCH_ASSOC)); echo var_dump($this->database); echo var_dump($data); echo var_dump($statement); }
Edited Galera, I solved briefly, sorry for the inconvenience.
Anyway, I did the
require_oncewithin the constructor of the class, and it worked, now I assign
$db_datato an attribute and I have everything inside the class.