/** * Wipe and re-initialize (mysql) database */ public static function init_db() { $rcmail = rcmail::get_instance(); $dsn = rcube_db::parse_dsn($rcmail->config->get('db_dsnw')); if ($dsn['phptype'] == 'mysql' || $dsn['phptype'] == 'mysqli') { // drop all existing tables first $db = $rcmail->get_dbh(); $db->query("SET FOREIGN_KEY_CHECKS=0"); $sql_res = $db->query("SHOW TABLES"); while ($sql_arr = $db->fetch_array($sql_res)) { $table = reset($sql_arr); $db->query("DROP TABLE {$table}"); } // init database with schema system(sprintf('cat %s %s | mysql -h %s -u %s --password=%s %s', realpath(INSTALL_PATH . '/SQL/mysql.initial.sql'), realpath(TESTS_DIR . 'Selenium/data/mysql.sql'), escapeshellarg($dsn['hostspec']), escapeshellarg($dsn['username']), escapeshellarg($dsn['password']), escapeshellarg($dsn['database']))); } else { if ($dsn['phptype'] == 'sqlite') { // delete database file -- will be re-initialized on first access system(sprintf('rm -f %s', escapeshellarg($dsn['database']))); } } }
<dl class="configblock" id="cgfblockdb"> <dt class="propname">db_dsnw</dt> <dd> <p>Database settings for read/write operations:</p> <?php $select_dbtype = new html_select(array('name' => '_dbtype', 'id' => "cfgdbtype")); foreach ($RCI->supported_dbs as $database => $ext) { if (extension_loaded($ext)) { $select_dbtype->add($database, substr($ext, 4)); } } $input_dbhost = new html_inputfield(array('name' => '_dbhost', 'size' => 20, 'id' => "cfgdbhost")); $input_dbname = new html_inputfield(array('name' => '_dbname', 'size' => 20, 'id' => "cfgdbname")); $input_dbuser = new html_inputfield(array('name' => '_dbuser', 'size' => 20, 'id' => "cfgdbuser")); $input_dbpass = new html_passwordfield(array('name' => '_dbpass', 'size' => 20, 'id' => "cfgdbpass")); $dsnw = rcube_db::parse_dsn($RCI->getprop('db_dsnw')); echo $select_dbtype->show($RCI->is_post ? $_POST['_dbtype'] : $dsnw['phptype']); echo '<label for="cfgdbtype">Database type</label><br />'; echo $input_dbhost->show($RCI->is_post ? $_POST['_dbhost'] : $dsnw['hostspec']); echo '<label for="cfgdbhost">Database server (omit for sqlite)</label><br />'; echo $input_dbname->show($RCI->is_post ? $_POST['_dbname'] : $dsnw['database']); echo '<label for="cfgdbname">Database name (use absolute path and filename for sqlite)</label><br />'; echo $input_dbuser->show($RCI->is_post ? $_POST['_dbuser'] : $dsnw['username']); echo '<label for="cfgdbuser">Database user name (needs write permissions)(omit for sqlite)</label><br />'; echo $input_dbpass->show($RCI->is_post ? $_POST['_dbpass'] : $dsnw['password']); echo '<label for="cfgdbpass">Database password (omit for sqlite)</label><br />'; ?> </dd> <dt class="propname">db_prefix</dt> <dd>