Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP get variables in class from another file

Tags:

oop

php

class

For example I have file config.php:

$host = 'localhost';
$db = 'logger';
$user = 'user';
$pwd = 'pass';

and file mysqlClass.php

class mysql{

public function connect(){

//hot get get variables form confing.php there ?
}

}

And I not know hot to get variables from confin.php in mysql class, I can't change config.php file

like image 765
user2287965 Avatar asked Apr 22 '13 19:04

user2287965


1 Answers

Just require_once() the file

public function connect() {
  require_once 'config.php';
  // ...code...
}
like image 175
flowfree Avatar answered Oct 06 '22 01:10

flowfree