Assigning database credentials I have a config.ini that contains my database credentials. I retrieve them with a parser class like this:

public function getField($section, $field) {
    return $this-&gt;iniArray[$section][$field];
}


In my DbConnect class I do this, which seems silly:

public function __construct() {
    $ini = new Configuration('configs/config.ini');
    $this-&gt;host = $ini-&gt;getField('Database', 'host');
    $this-&gt;user = $ini-&gt;getField('Database', 'user');
    $this-&gt;pass = $ini-&gt;getField('Database', 'password');
    $this-&gt;dbname = $ini-&gt;getField('Database', 'name');


I'm sure there is a better way to set these values, but I'm not sure how.
Perhaps instead of an ini file, a JSON would suit the purpose better. I've seen this multiple times, even in large, well-known PHP frameworks.

You can find a lot about decoding JSON from the docs. Here's a little blog post about handling decoding. And here's a StackOverflow question regarding the external file.



Also, if you keep the same class, I suggest passing Configuration through the constructor to practice dependency injection.

public function __construct(Configuration $ini) {
    $this-&gt;host = $ini-&gt;getField('Database', 'host');
    $this-&gt;user = $ini-&gt;getField('Database', 'user');
    $this-&gt;pass = $ini-&gt;getField('Database', 'password');
    $this-&gt;dbname = $ini-&gt;getField('Database', 'name');
}