Rev 44 | Rev 48 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 44 | Rev 47 | ||
---|---|---|---|
Line 137... | Line 137... | ||
137 | $this->_options = $options; |
137 | $this->_options = $options; |
138 | }
|
138 | }
|
139 | }
|
139 | }
|
140 | 140 | ||
141 | /**
|
141 | /**
|
- | 142 | * Reads the connection configuration for this database
|
|
- | 143 | * from the configuration file, application/.config
|
|
- | 144 | *
|
|
- | 145 | * There must be an INI section named "database:" followed
|
|
- | 146 | * by the value of the <code>$_dbname</code> property
|
|
- | 147 | * containing keys and values for the properties of the
|
|
- | 148 | * <code>Database</code> instance. Except for the key
|
|
- | 149 | * <code>dbname</code>, which allows for aliases, all
|
|
- | 150 | * keys are ignored if the corresponding properties
|
|
- | 151 | * were set. That is, definitions in the class file
|
|
- | 152 | * override those in the configuration file.
|
|
- | 153 | *
|
|
- | 154 | * @return boolean|array
|
|
- | 155 | * <code>true</code> if the configuration
|
|
- | 156 | * file could be read, the configuration array otherwise.
|
|
- | 157 | */
|
|
- | 158 | public function readConfig () |
|
- | 159 | {
|
|
- | 160 | $config = parse_ini_file('application/.config', true); |
|
- | 161 | if ($config !== false) |
|
- | 162 | {
|
|
- | 163 | $section = 'database:' . $this->_dbname; |
|
- | 164 | if (isset($config[$section])) |
|
- | 165 | {
|
|
- | 166 | $dbconfig = $config[$section]; |
|
- | 167 | foreach (array('host', 'dbname', 'username', 'password', 'charset') as $key) |
|
- | 168 | {
|
|
- | 169 | $property = "_$key"; |
|
- | 170 | if (isset($dbconfig[$key]) |
|
- | 171 | && $key == 'dbname' |
|
- | 172 | || (property_exists($this, $property) |
|
- | 173 | && $this->$property === null)) |
|
- | 174 | {
|
|
- | 175 | $this->$property = $dbconfig[$key]; |
|
- | 176 | }
|
|
- | 177 | }
|
|
- | 178 | }
|
|
- | 179 | }
|
|
- | 180 | ||
- | 181 | return $config; |
|
- | 182 | }
|
|
- | 183 | ||
- | 184 | /**
|
|
142 | * @return PDO
|
185 | * @return PDO
|
143 | */
|
186 | */
|
144 | public function getConnection () |
187 | public function getConnection () |
145 | {
|
188 | {
|
146 | if ($this->_connection === null) |
189 | if ($this->_connection === null) |