public static function getGroupName($groupid) { $groupid = DB::escape($groupid); $sql = 'SELECT name FROM ' . TABLE_PREFIX . 'groups WHERE id=' . $groupid; return DB::get_var($sql); }
/** * DROPS all tables in the test DB that might be there from previous tests. */ function dropTestDbTables() { global $db_config; $test_tables = $this->test_DB->get_col('SHOW TABLES LIKE "' . $GLOBALS['tableprefix'] . '%"'); if (!$test_tables) { // nothing to drop return; } $old_fk_check = $this->test_DB->get_var('SELECT @@FOREIGN_KEY_CHECKS'); $this->test_DB->query('SET FOREIGN_KEY_CHECKS = 0;'); $drop_query = 'DROP TABLE IF EXISTS ' . implode(', ', $test_tables); $this->test_DB->query($drop_query); /* // dh> deactivated due to easy-tests-setup, using another tableprefix. // Does not seem to be required anymore. After running all tests, the // (separate) DB is empty. // // Now drop all "evo_%" tables, which may not have been handled from // the alias definitions above (e.g. "evo_posts" for the 0.8 upgrade // test) if( $test_tables = $this->test_DB->get_col( 'SHOW TABLES LIKE "evo_%"' ) ) { $drop_query = 'DROP TABLE IF EXISTS '.implode( ', ', $test_tables ); $this->test_DB->query( $drop_query ); } */ if (!empty($old_fk_check)) { $this->test_DB->query('SET FOREIGN_KEY_CHECKS = ' . $old_fk_check . ';'); } }
public static function getRankImage($rank) { $sql = 'SELECT `rankimage` FROM ' . TABLE_PREFIX . 'ranks WHERE rank="' . $rank . '"'; return DB::get_var($sql); }
/** * */ public static function get_var($i_column, array $i_opts = []) { return DB::get_var(self::db_table_name(), $i_column, $i_opts); }
/** * Setup required globals */ function setUp() { global $FileRootCache, $FiletypeCache, $FileCache, $GroupCache, $DB, $db_config, $Debuglog, $Messages, $UserCache, $Timer, $Plugins, $Settings, $UserSettings; global $allow_evodb_reset; parent::setUp(); // just because.. $Debuglog = new Log('note'); $Messages = new Log('error'); $FileRootCache = new FileRootCache(); $UserCache = new UserCache(); $FileCache = new FileCache(); $FileRootCache = new FileRootCache(); $FiletypeCache = new FiletypeCache(); $GroupCache = new DataObjectCache('Group', true, 'T_groups', 'grp_', 'grp_ID'); $Timer = new Timer(); $Plugins = new Plugins_admin_no_DB(); $db_params = $db_config; $db_params['new_link'] = true; // needed to not interfere with the DB connection to the test DB (setup in EvoDbUnitTestCase). $DB = new DB($db_params); /* if( $DB->query('SHOW TABLES LIKE "T_settings"') && ! get_db_version() ) { // DB tables created, but no data loaded // Let's delete it and reinstall echo '<h2>'.T_('Deleting b2evolution tables from the datatase...').'</h2>'; evo_flush(); if( $allow_evodb_reset != 1 ) { echo T_('If you have installed b2evolution tables before and wish to start anew, you must delete the b2evolution tables before you can start a new installation. b2evolution can delete its own tables for you, but for obvious security reasons, this feature is disabled by default.'); echo '<p>'.sprintf( T_('To enable it, please go to the %s file and change: %s to %s'), '/conf/_basic_config.php', '<pre>$allow_evodb_reset = 0;</pre>', '<pre>$allow_evodb_reset = 1;</pre>' ).'</p>'; echo '<p>'.T_('Then reload this page and a reset option will appear.').'</p>'; echo '<p><a href="index.php?locale='.$default_locale.'">« '.T_('Back to install menu').'</a></p>'; die(); } // $this->create_current_tables(); db_delete(); echo '<h2>Tables deleted</h2>'; } if( ! $DB->query('SHOW TABLES LIKE "T_settings"') && ! get_db_version() ) { // b2evolution is not installed, let's run the installer global $inc_path, $modules, $default_locale, $evo_charset, $current_charset, $current_locale; // This initializes table name aliases and is required before trying to connect to the DB. load_class( '_core/model/_module.class.php', 'Module' ); foreach( $modules as $module ) { require_once $inc_path.$module.'/_'.$module.'.init.php'; } // Let the modules load/register what they need: modules_call_method( 'init' ); // Load all available locale defintions: locales_load_available_defs(); // Activate default locale: if( ! locale_activate( $default_locale ) ) { // Could not activate locale (non-existent?), fallback to en-US: $default_locale = 'en-US'; locale_activate( 'en-US' ); } init_charsets( $current_charset ); // fp> TODO: this test should probably be made more generic and applied to upgrade too. $expected_connection_charset = $DB->php_to_mysql_charmap($evo_charset); if( $DB->connection_charset != $expected_connection_charset ) { echo '<div class="error"><p class="error">'.sprintf( T_('In order to install b2evolution with the %s locale, your MySQL needs to support the %s connection charset.').' (mysqli::set_charset(%s))', $current_locale, $evo_charset, $expected_connection_charset ).'</p></div>'; // sam2kb> TODO: If something is not supported we can display a message saying "do this and that, enable extension X etc. etc... or switch to a better hosting". die(); } //$this->create_current_tables(); // NOTE: this is the same as with install action "newdb": echo '<h2>Manual</h2>'; //install_newdb(); } */ // Check if settings table exists then DB is installed $db_is_installed = (bool) $DB->get_var('SHOW TABLES LIKE "T_settings"'); if (!$db_is_installed) { // A dirty workaround for GeneralSettings::_construct // where it checks $new_db_version against unexisting db_version because b2evo is not installed yet $tmp = $GLOBALS['new_db_version']; $GLOBALS['new_db_version'] = false; } $Settings = new GeneralSettings(); $UserSettings = new UserSettings(); if (!$db_is_installed) { // Revert $new_db_version to real value after dirty hack above $GLOBALS['new_db_version'] = $tmp; } // Reload conf and vars. require EVODIR . 'blogs/conf/_config.php'; require EVODIR . 'blogs/inc/_main.inc.php'; $this->_saved_globals = array(); $this->_saved_server = array(); }
/** * Perform a Database Query */ public function query($archive = null, $arguments = array()) { switch ($archive) { // case '_next': // Load the the Next (Newer) Post // $sql = "SELECT * FROM `{$this->config->db_prefix}posts` WHERE `published` = '1' AND `id` != '{$this->id}' AND `date` >= '{$this->date_raw}' AND `date` <= CURRENT_TIMESTAMP ORDER BY `date` ASC LIMIT 1"; // break; // case '_prev': // Load the the Previous (Older) Post // case '_previous': // Alias for _prev // $sql = "SELECT * FROM `{$this->config->db_prefix}posts` WHERE `published` = '1' AND `id` != '{$this->id}' AND `date` <= '{$this->date_raw}' AND `date` <= CURRENT_TIMESTAMP ORDER BY `date` DESC LIMIT 1"; // break; case '_total': // Total posts $sql = "SELECT count(`id`) FROM `{$this->config->db_prefix}posts` WHERE `published` = '1' AND `date` <= CURRENT_TIMESTAMP ORDER BY `date` DESC"; return (int) DB::get_var($sql); break; case '_posts': // Load all of the posts // Load all of the posts case '': default: $sql = "SELECT * FROM `{$this->config->db_prefix}posts` WHERE `published` = '1' AND `date` <= CURRENT_TIMESTAMP ORDER BY `date` DESC"; break; } return DB::get_results($sql); }