/** * */ public static function reconnect() { if (isset(_db::$con_name) && isset(_db::$con_arr[_db::$con_name]) && isset(_db::$con_arr[_db::$con_name]['settings'])) { $settings = _db::$con_arr[_db::$con_name]['settings']; _db::connect($settings['host'], $settings['database'], $settings['username'], $settings['password'], _db::$con_name); } else { _db::default_connection(); } }
public function do_submit() { db::connect_root(); db::query('CREATE DATABASE IF NOT EXISTS `' . get::fn($this->username) . '`'); db::query('USE mysql'); if (db::select('user')->retrieve(['user'])->filter(['`user`=:user AND `host`=:host'], ['user' => $this->username, 'host' => '127.0.0.1'])->execute()->rowCount()) { db::query('CREATE USER \'' . get::fn($this->username) . '\'@\'127.0.0.1\' IDENTIFIED BY \'' . $this->password . '\'', [], true); } if (db::select('user')->retrieve(['user'])->filter(['`user`=:user AND `host`=:host'], ['user' => $this->username, 'host' => 'localhost'])->execute()->rowCount()) { db::query('CREATE USER \'' . get::fn($this->username) . '\'@\'localhost\' IDENTIFIED BY \'' . $this->password . '\'', [], true); } db::query('GRANT ALL PRIVILEGES ON `' . get::fn($this->username) . '`.* TO \'' . get::fn($this->username) . '\'@\'127.0.0.1\'', [], true); db::query('GRANT ALL PRIVILEGES ON `' . get::fn($this->username) . '`.* TO \'' . get::fn($this->username) . '\'@\'localhost\'', [], true); if (!is_dir(root . '/.conf')) { mkdir(root . '/.conf'); } ini::save(root . '/.conf/config.ini', ['mysql' => ['server' => '127.0.0.1', 'username' => get::fn($this->username), 'password' => $this->password, 'database' => get::fn($this->username)], 'site' => ['title_tag' => $this->site_name]]); ini::reload(); db::default_connection(); $cms_builder = new \module\cms\object\cms_builder(); $cms_builder->manage(); $i = 0; do { if ($this->{'user_' . $i} && $this->{'password_' . $i}) { $user = new _cms_user(); $user->title = $this->{'user_' . $i}; $user->password = $this->{'password_' . $i}; $user->ulid = $this->{'user_level_' . $i} ?: 1; } $i++; } while (isset($this->{'user_' . $i})); ajax::current()->redirect = '/cms/login'; }
<?php use classes\db; define('load_core', false); include '../../index.php'; db::default_connection(); db::connect('localhost', 'nxcl_old', 'root', '', 'old'); set_time_limit(0); $tables = array('flight' => array('ID' => 'fid', 'Pilot_No' => 'pid', 'Club_No' => 'cid', 'Glider_No' => 'gid', 'Base_Score' => 'base_score', 'Score' => 'score', 'Multi' => 'multi', 'Date' => 'date', 'Season' => 'season', 'DateAdded' => 'created', 'Cords' => 'coords', 'Launch' => 'lid', 'Type' => 'ftid', 'Defined' => 'defined', 'Ridge' => 'ridge', 'Winter' => 'winter', 'Vis_Info' => 'info', 'Admin_Info' => 'admin_info', 'Personal' => 'personal', 'Delay' => 'delayed', 'Comp' => 'comp_id', 'dim' => 'did', 'flighttime' => 'duration', 'ODs' => 'od_score', 'ODt' => 'od_time', 'ORs' => 'or_score', 'ORt' => 'or_time', 'TRs' => 'tr_score', 'TRt' => 'tr_time', 'Speed' => 'speed'), 'pilot' => array('P_ID' => 'pid', 'P_NAME' => 'name', 'Gender' => 'gender', 'BHPA' => 'bhpa_no', 'Rating' => 'rating', 'Email' => 'email'), 'glider' => array('G_ID' => 'gid', 'G_NAME' => 'name', 'G_CLASS' => 'class', 'Manufacturer' => array('get_manu', 'mid'), 'Kingpost' => 'kingpost', 'Single_Surface' => 'single_surface', 'Hangies_League' => 'hangies'), 'waypoint' => array('ID' => 'wid', 'INFO' => 'title', 'Lat' => 'lat', 'Lon' => 'lon')); foreach ($tables as $table => $keys) { echo '<h1>Importing: ' . $table . '</h1>'; db::swap_connection('old'); $res = db::query('SELECT * FROM ' . $table . 's'); db::swap_connection('default'); db::query('TRUNCATE ' . $table); // prepare_statement $sql_arr = []; $key_arr = []; foreach ($keys as $old => $new) { if (is_array($new)) { $sql_arr[] = '`' . $new[1] . '`'; } else { $sql_arr[] = '`' . $new . '`'; } $key_arr[] = ':' . $old . '_[id]'; } $base_sql = 'INSERT INTO ' . $table . ' (' . implode(', ', $sql_arr) . ') VALUES '; $key_set = '(' . implode(', ', $key_arr) . ')'; $part_cnt = 0; $cnt = 0; $params = [];