Rev 68 | Rev 74 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 68 | Rev 69 | ||
|---|---|---|---|
| Line 156... | Line 156... | ||
| 156 | * The configuration array if the configuration
|
156 | * The configuration array if the configuration
|
| 157 | * file could be read, <code>false</code> otherwise.
|
157 | * file could be read, <code>false</code> otherwise.
|
| 158 | */
|
158 | */
|
| 159 | public function readConfig () |
159 | public function readConfig () |
| 160 | {
|
160 | {
|
| - | 161 | /* FIXME: Configuration file path should not be hardcoded */
|
|
| 161 | $config = parse_ini_file('application/.config', true); |
162 | $config = parse_ini_file('application/.config', true); |
| 162 | if ($config !== false) |
163 | if ($config !== false) |
| 163 | {
|
164 | {
|
| 164 | $section = 'database:' . $this->_dbname; |
165 | $section = 'database:' . $this->_dbname; |
| 165 | if (isset($config[$section])) |
166 | if (isset($config[$section])) |
| 166 | {
|
167 | {
|
| 167 | $dbconfig = $config[$section]; |
168 | $dbconfig = $config[$section]; |
| 168 | $options = array( |
169 | $options = array( |
| 169 | 'host', 'port', 'dbname', 'username', 'password', 'charset' |
170 | 'host', 'port', 'dbname', 'username', 'password', 'charset' |
| 170 | ); |
171 | ); |
| 171 | 172 | ||
| 172 | foreach ($options as $key) |
173 | foreach ($options as $key) |
| 173 | {
|
174 | {
|
| 174 | $property = "_$key"; |
175 | $property = "_$key"; |
| 175 | if (isset($dbconfig[$key]) |
176 | if (isset($dbconfig[$key]) |
| 176 | && $key == 'dbname' |
177 | && ($key == 'dbname' |
| 177 | || (property_exists($this, $property) |
178 | || (property_exists($this, $property) |
| 178 | && $this->$property === null)) |
179 | && $this->$property === null))) |
| 179 | {
|
180 | {
|
| 180 | $this->$property = $dbconfig[$key]; |
181 | $this->$property = $dbconfig[$key]; |
| 181 | }
|
182 | }
|
| 182 | }
|
183 | }
|
| 183 | - | ||
| 184 | return $config[$section]; |
- | |
| 185 | }
|
- | |
| 186 | }
|
- | |
| 187 | 184 | ||
| - | 185 | return $config[$section]; |
|
| - | 186 | }
|
|
| - | 187 | }
|
|
| - | 188 | ||
| 188 | return $config; |
189 | return $config; |
| 189 | }
|
190 | }
|
| 190 | 191 | ||
| 191 | /**
|
192 | /**
|
| 192 | * @return PDO
|
193 | * @return PDO
|
| 193 | */
|
194 | */
|
| Line 259... | Line 260... | ||
| 259 | * @param string $column_name
|
260 | * @param string $column_name
|
| 260 | * @return string
|
261 | * @return string
|
| 261 | */
|
262 | */
|
| 262 | protected function _columnDef (array $data, $column_name) |
263 | protected function _columnDef (array $data, $column_name) |
| 263 | {
|
264 | {
|
| 264 | $def = (isset($data['unsigned']) && $data['unsigned'] ? 'UNSIGNED ' : '') |
265 | $def = (isset($data['unsigned']) && $data['unsigned'] ? 'UNSIGNED ' : '') |
| 265 | . $data['type'] |
266 | . $data['type'] |
| 266 | . (isset($data['not_null']) && $data['not_null'] ? ' NOT NULL' : ' NULL') |
267 | . (isset($data['not_null']) && $data['not_null'] ? ' NOT NULL' : ' NULL') |
| 267 | . (isset($data['default']) && $data['default'] ? " DEFAULT {$data['default']}" : '') |
268 | . (isset($data['default']) && $data['default'] ? " DEFAULT {$data['default']}" : '') |
| 268 | . (isset($data['auto_inc']) && $data['auto_inc'] ? ' AUTO_INCREMENT' : '') |
269 | . (isset($data['auto_inc']) && $data['auto_inc'] ? ' AUTO_INCREMENT' : '') |
| 269 | . (isset($data['unique']) && $data['unique'] ? ' UNIQUE KEY' : '') |
270 | . (isset($data['unique']) && $data['unique'] ? ' UNIQUE KEY' : '') |
| 270 | . (isset($data['primary']) && $data['primary'] ? ' PRIMARY KEY' : '') |
271 | . (isset($data['primary']) && $data['primary'] ? ' PRIMARY KEY' : '') |
| 271 | . (isset($data['comment']) && $data['comment'] ? " COMMENT '{$data['comment']}'" : ''); |
272 | . (isset($data['comment']) && $data['comment'] ? " COMMENT '{$data['comment']}'" : ''); |
| 272 | 273 | ||
| 273 | return $this->escapeName($column_name) . ' ' . $def; |
274 | return $this->escapeName($column_name) . ' ' . $def; |
| 274 | }
|
275 | }
|
| 275 | 276 | ||
| 276 | /**
|
277 | /**
|
| 277 | * Creates a database table according to the specified parameters
|
278 | * Creates a database table according to the specified parameters
|
| 278 | *
|
279 | *
|
| Line 283... | Line 284... | ||
| 283 | * @return bool
|
284 | * @return bool
|
| 284 | * @see PDOStatement::execute()
|
285 | * @see PDOStatement::execute()
|
| 285 | */
|
286 | */
|
| 286 | public function createTable ($name, array $columns, array $options = null) |
287 | public function createTable ($name, array $columns, array $options = null) |
| 287 | {
|
288 | {
|
| 288 | $class = \get_class($this); |
289 | $class = \get_class($this); |
| 289 | $query = 'CREATE TABLE ' |
290 | $query = 'CREATE TABLE ' |
| 290 | . $this->escapeName($name) |
291 | . $this->escapeName($name) |
| 291 | . '(' |
292 | . '(' |
| 292 | . array_map(array($this, '_columnDef'), $columns, array_keys($columns)) . ')'; |
293 | . array_map(array($this, '_columnDef'), $columns, array_keys($columns)) . ')'; |
| 293 | 294 | ||
| 294 | $stmt = $this->prepare($query); |
295 | $stmt = $this->prepare($query); |
| 295 | 296 | ||
| 296 | /* DEBUG */
|
297 | /* DEBUG */
|
| 297 | if (defined('DEBUG') && DEBUG > 1) |
298 | if (defined('DEBUG') && DEBUG > 1) |
| 298 | {
|
299 | {
|
| 299 | debug(array( |
300 | debug(array( |
| 300 | 'query' => $query, |
301 | 'query' => $query, |
| 301 | )); |
302 | )); |
| Line 637... | Line 638... | ||
| 637 | 638 | ||
| 638 | /* DEBUG */
|
639 | /* DEBUG */
|
| 639 | if (defined('DEBUG') && DEBUG > 1) |
640 | if (defined('DEBUG') && DEBUG > 1) |
| 640 | {
|
641 | {
|
| 641 | debug(array( |
642 | debug(array( |
| 642 | 'query' => $query, |
643 | 'query' => $query, |
| 643 | 'params' => $params |
644 | 'params' => $params |
| 644 | )); |
645 | )); |
| 645 | }
|
646 | }
|
| 646 | 647 | ||
| 647 | $success =& $this->_lastSuccess; |
648 | $success =& $this->_lastSuccess; |
| 648 | $success = $stmt->execute($params); |
649 | $success = $stmt->execute($params); |