0

I have $mo_conf variable in a script named config.php and I want to acess it from another script mo_model.php. Both are in different directories.

The code:

config.php

$mo_conf['user'] = "root";
$mo_conf['password'] = "passwd";
$mo_conf['host'] = "localhost";
$mo_conf['database'] = "itienda";

mo_model.php

class MO_Model extends MO_Object
{
  private $con;

  static function db_connect()
   {
     $con = mysqli_connect($mo_conf['host'],$mo_conf['usr'],$mo_conf['password'],$mo_conf['database']);
   } 
 }

After running the script the following notice is displayed:

Notice: Undefined variable: $mo_conf in C:\m\core\mo_model.php on line 59

What's wrong?

Thanks.

axmug
  • 476
  • 2
  • 10
  • 26
  • 1
    You have to include `config.php` into `mo_model.php`! Otherwise how should php know that you have variables in another file?! – Rizier123 Apr 22 '15 at 18:53
  • To add to @Rizier123. If the configs never gonna change why not define the config as constants. – frz3993 Apr 22 '15 at 18:54
  • I included the config.php file into mo_model.php in the following line: require_once(config/config.php); – axmug Apr 22 '15 at 19:07

0 Answers0