blob: d7a6351a0d2cd91a726b437049080ac6bfaec8f9 [file] [log] [blame]
Taufan Aditya655a89f2012-03-29 03:00:56 +07001<?php
2
3class Mock_Database_DB {
4
5 private $config = array();
6
7 /**
8 * Prepare database configuration skeleton
9 *
10 * @param array DB configuration to set
11 * @return void
12 */
13 public function __construct($config = array())
14 {
15 include_once(BASEPATH.'database/DB.php');
16
17 $this->config = $config;
18 }
19
20 public function set_config($group = 'default')
21 {
22 if ( ! isset($this->config[$group]))
23 {
24 throw new InvalidArgumentException('Group '.$group.' not exists');
25 }
26
27 if ( ! empty($this->config[$group]['dsn']))
28 {
29 $dsn = $this->config[$group]['dsn'];
30 }
31 else
32 {
33 $config = $this->config[$group];
34 $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password']
35 .'@'.$config['hostname'].'/'.$config['database'];
36
37 }
38
39 $params = array_slice($this->config[$group], 6);
40
41 return $dsn.http_build_query($params);
42 }
43}