Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Form_model extends CI_Model
- {
- function check()
- {
- $this -> load -> helper(array('form', 'url'));
- $this -> load -> library('form_validation');
- $this -> form_validation -> set_rules('db_driver', 'db_driver', 'required');
- $this -> form_validation -> set_rules('db_hostname', 'db_hostname', 'required');
- $this -> form_validation -> set_rules('db_username', 'db_username', 'required');
- $this -> form_validation -> set_rules('db_password', 'Password');
- $this -> form_validation -> set_rules('db_database', 'db_database', 'required');
- $this -> form_validation -> set_rules('db_prefix', 'db_prefix');
- if ($this -> form_validation -> run() == false) {
- return FALSE;
- } else {
- $dbconfig['hostname'] = $this -> input -> post('db_hostname');
- $dbconfig['username'] = $this -> input -> post('db_username');
- $dbconfig['password'] = $this -> input -> post('db_password');
- $dbconfig['database'] = $this -> input -> post('db_database');
- $dbconfig['dbprefix'] = $this -> input -> post('db_prefix');
- //$dbconfig['pconnect'] = ($this->input->post('pconnect')) ? TRUE : TRUE;
- $dbconfig['dbdriver'] = 'mysqli';
- $this -> load -> helper('file');
- $prototype = array('hostname' => '', 'username' => '', 'password' => '', 'database' => '', 'dbdriver' => '', 'dbprefix' => '', 'pconnect' => true, 'db_debug' => false, 'cache_on' => false, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci');
- // Now we read the file data as a string
- $config_file = read_file(self::$path);
- //self::$content = $config_file;
- //$this->set_config('hostname','localhost');
- // Dollar signs seem to create a problem with our preg_replace
- // so we'll temporarily swap them out
- $config_file = str_replace('$', '@s@', $config_file);
- // Cycle through the newconfig array and swap out the data
- if (count($dbconfig) > 0) {
- $active_group = 'default';
- foreach ($dbconfig as $key => $val) {
- if ($val === 'y') {
- $val = true;
- } elseif ($val == 'n') {
- $val = false;
- }
- if (is_bool($val)) {
- $val = ($val == true) ? 'TRUE' : 'FALSE';
- } else {
- $val = '\'' . $val . '\'';
- }
- $val .= ';';
- // Update the value
- $config_file = preg_replace("#(\@s\@db\[(['\"])" . $active_group . "\\2\]\[(['\"])" . $key . "\\3\]\s*=\s*).*?;#", "\\1$val", $config_file);
- }
- }
- return TRUE;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement