139,6 → 139,49 |
} |
|
/** |
* Reads the connection configuration for this database |
* from the configuration file, application/.config |
* |
* There must be an INI section named "database:" followed |
* by the value of the <code>$_dbname</code> property |
* containing keys and values for the properties of the |
* <code>Database</code> instance. Except for the key |
* <code>dbname</code>, which allows for aliases, all |
* keys are ignored if the corresponding properties |
* were set. That is, definitions in the class file |
* override those in the configuration file. |
* |
* @return boolean|array |
* <code>true</code> if the configuration |
* file could be read, the configuration array otherwise. |
*/ |
public function readConfig () |
{ |
$config = parse_ini_file('application/.config', true); |
if ($config !== false) |
{ |
$section = 'database:' . $this->_dbname; |
if (isset($config[$section])) |
{ |
$dbconfig = $config[$section]; |
foreach (array('host', 'dbname', 'username', 'password', 'charset') as $key) |
{ |
$property = "_$key"; |
if (isset($dbconfig[$key]) |
&& $key == 'dbname' |
|| (property_exists($this, $property) |
&& $this->$property === null)) |
{ |
$this->$property = $dbconfig[$key]; |
} |
} |
} |
} |
|
return $config; |
} |
|
/** |
* @return PDO |
*/ |
public function getConnection () |