Jump to content

how to access these


Hailwood

Recommended Posts

hi guys,

 

I need to know how to access these

 

if im doing this:

$this->config = Config::getInstance();


        print_r($this->config);

 

 

and its spitting out:

 

 


Config Object
(
    [base] => Array
        (
            [abs_path] => C:/server/xampp/htdocs/***/
            [url_path] => http://localhost/***/
            [temp_dir] => tmp/
            [env] => dev
        )


    [database] => Array
        (
            [host] => localhost
            [user] => root
            [pass] => 
            [name] => ***
        )


    [mconnect] => Array
        (
            [url=http://=> ***
            [appname] => ***
            [password] => ***
            [msgclass] => ***
        )


    [interfax] => Array
        (
             => ***
            [username] => ***
            [password] => ***
            [filetype] => HTML
        )


)

so what goes in place of this question mark if i want to get the database name?
$this->config->?


Ive tried $this->config->database['name'];


but i get cannot access empty property] => ***
            [appname] => ***
            [password] => ***
            [msgclass] => ***
        )


    [interfax] => Array
        (
             => ***
            [username] => ***
            [password] => ***
            [filetype] => HTML
        )


)

so what goes in place of this question mark if i want to get the database name?

$this->config->?

 

 

Ive tried $this->config->database['name'];

 

 

but i get cannot access empty property

Link to comment
https://forums.phpfreaks.com/topic/203201-how-to-access-these/
Share on other sites

dunno if it will help but this is how i store the info


//GET AN INSTANCE OF THE CONFIG CLASS
$config = Config::getInstance();

//DATABASE SETTINGS
//------------------
$config->database = array();
$config->database['host'] = 'localhost';
$config->database['user'] = 'root';
$config->database['pass'] = '';
$config->database['name'] = 'buzzil';

the config class has


    public static function getInstance() {
        if (self::$instance== null)
            self::$instance= new config();
        return self::$instance;
    }

    public function __set($k, $v) {$this->$k = $v;}
    public function __get($k) {return $this->$k;}

 

Link to comment
https://forums.phpfreaks.com/topic/203201-how-to-access-these/#findComment-1064673
Share on other sites

strange this is if i do this:


$this->link = $this->config->database['pass'];                             //line 45
        $this->$link = mysql_connect(                                          //line 46
                $this->config->database['host'],  //Database Host
                $this->config->database['user'],  //Database User
                $this->config->database['pass']); //Database Pass

 

 

i get

Fatal error: Cannot access empty property inC:\server\xampp\htdocs\buzzil2\classes\database.class.php on line 46so why dont i get this error on 45?

wondering if one of the values was not set properly i went through and changed 45 to user/host/pass/ in turn, but still no error

Link to comment
https://forums.phpfreaks.com/topic/203201-how-to-access-these/#findComment-1064679
Share on other sites

 

Current Status

Attempt: $this->config->database['name'];

Error: cannot access empty property

 

 

Attempt: $this->config->database->name;

Error: cannot access empty property

 

 

Attempt: $this->config[database][name];

Error: Cannot use object of type Config as array

 

 

Attempt: $this->config->[database][name];

Error: Incorrect Syntax

Link to comment
https://forums.phpfreaks.com/topic/203201-how-to-access-these/#findComment-1064685
Share on other sites

ok, so you know the times when you feel really stupid?

 

yeah this is one of them,

 

i can get to them doing $this->config->database['name'];

 

the error had nothing to do with me trying to access them,

 

the error was because i was doing

$this->$link

by accident instead of

$this->link

Link to comment
https://forums.phpfreaks.com/topic/203201-how-to-access-these/#findComment-1064688
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.