/** * Write all of the SQL tables to the database * * @return */ public static function AddTables() { if (!DB::init($_POST['DBASE_TYPE'])) { self::$error = DB::$error; return false; } DB::set_caching(false); $ret = DB::connect($_POST['DBASE_USER'], $_POST['DBASE_PASS'], $_POST['DBASE_NAME'], $_POST['DBASE_SERVER']); if ($ret == false) { self::$error = DB::$error; return false; } if (!DB::select($_POST['DBASE_NAME'])) { self::$error = DB::$error; return false; } DB::$throw_exceptions = false; echo '<h2>Writing Tables...</h2>'; $sqlLines = self::readSQLFile(SITE_ROOT . '/install/sql/install.sql', $_POST['TABLE_PREFIX']); foreach ($sqlLines as $sql) { DB::query($sql['sql']); if (DB::errno() != 0) { #echo 'failed - manually run this query: <br /><br />"'.$sql.'"'; echo '<div id="error" style="text-align: left;">Writing "' . $sql['table'] . '" table... '; echo "<br /><br />" . DB::error(); echo '</div>'; } } echo "Wrote {$totalTables} tables<br />"; echo '<h2>Populating Initial Data...</h2>'; $sqlLines = self::readSQLFile(SITE_ROOT . '/install/fixtures/install.sql', $_POST['TABLE_PREFIX']); foreach ($sqlLines as $sql) { DB::query($sql['sql']); if (DB::errno() != 0) { echo '<div id="error" style="text-align: left;">Writing to "' . $sql['table'] . '" table... '; echo "<br /><br />" . DB::error(); echo '</div>'; } } return true; }
@(include CORE_PATH . DS . 'local.config.php'); /* Set the language */ Lang::set_language(Config::Get('SITE_LANGUAGE')); error_reporting(Config::Get('ERROR_LEVEL')); Debug::$debug_enabled = Config::Get('DEBUG_MODE'); if (Debug::$debug_enabled == true) { ini_set('log_errors', 'On'); ini_set('display_errors', 'Off'); ini_set('error_log', LOGS_PATH . '/errors.txt'); } /* Init caching engine */ CodonCache::init($cache_settings); if (DBASE_NAME != '' && DBASE_SERVER != '' && DBASE_NAME != 'DBASE_NAME') { require CLASS_PATH . DS . 'ezdb/ezdb.class.php'; DB::$show_errors = Config::Get('DEBUG_MODE'); DB::$throw_exceptions = false; DB::init(DBASE_TYPE); DB::set_log_errors(Config::Get('DEBUG_MODE')); DB::set_error_handler(array('Debug', 'db_error')); DB::set_caching(false); DB::$table_prefix = TABLE_PREFIX; DB::set_cache_dir(CACHE_PATH); DB::$DB->debug_all = false; if (Config::Get('DEBUG_MODE') == true) { DB::show_errors(); } else { DB::hide_errors(); } if (!DB::connect(DBASE_USER, DBASE_PASS, DBASE_NAME, DBASE_SERVER)) { Debug::showCritical(Lang::gs('database.connection.failed') . ' (' . DB::$errno . ': ' . DB::$error . ')'); die;
public static function set_throw_exceptions($bool) { self::$throw_exceptions = $bool; }
public static function AddTables() { // Write the SQL Tables, from install.sql // first connect: if (!DB::init($_POST['DBASE_TYPE'])) { self::$error = DB::$error; return false; } $ret = DB::connect($_POST['DBASE_USER'], $_POST['DBASE_PASS'], $_POST['DBASE_NAME'], $_POST['DBASE_SERVER']); if ($ret == false) { self::$error = DB::$error; return false; } if (!DB::select($_POST['DBASE_NAME'])) { self::$error = DB::$error; return false; } DB::$throw_exceptions = false; // 1 table at a time - read upto a ; and then // run the query $sql = ''; $sql_file = file_get_contents(SITE_ROOT . '/install/install.sql'); $revision = file_get_contents(SITE_ROOT . '/core/version'); for ($i = 0; $i < strlen($sql_file); $i++) { $str = $sql_file[$i]; if ($str == ';') { $sql .= $str; $sql = str_replace('phpvms_', $_POST['TABLE_PREFIX'], $sql); $sql = trim($sql); preg_match("/({$_POST['TABLE_PREFIX']}.*)` /", $sql, $matches); $tablename = $matches[1]; // Skip if it's a comment if ($sql[0] == '-' && $sql[1] == '-') { $sql = ''; continue; } if ($tablename == '') { $sql = ''; continue; } $sql = str_replace('##REVISION##', $revision, $sql); DB::query($sql); if (DB::errno() != 0) { $divid = 'error'; } else { $divid = 'success'; } echo '<div id="' . $divid . '" style="text-align: left;">Writing "' . $tablename . '" table... '; if (DB::errno() != 0) { echo 'failed - manually run this query: <br /><br />"' . $sql . '"'; } else { echo 'success'; } echo '</div>'; $sql = ''; } else { $sql .= $str; } } return true; }