protected function createTable() { $this->debug('createTable: Check if plugin table exists.'); // Create plugin table if doesn't exist $query = "SHOW TABLES LIKE '{$this->db->getPrefix()}kunenadiscuss'"; $this->db->setQuery($query); if (!$this->db->loadResult()) { KunenaError::checkDatabaseError(); $query = "CREATE TABLE IF NOT EXISTS `#__kunenadiscuss`\n\t\t\t\t\t(`content_id` int(11) NOT NULL default '0',\n\t\t\t\t\t `thread_id` int(11) NOT NULL default '0',\n\t\t\t\t\t PRIMARY KEY (`content_id`)\n\t\t\t\t\t )"; $this->db->setQuery($query); $this->db->query(); KunenaError::checkDatabaseError(); $this->debug("Created #__kunenadiscuss cross reference table."); // Migrate data from old FireBoard discussbot if it exists $query = "SHOW TABLES LIKE '{$this->db->getPrefix()}fb_discussbot'"; $this->db->setQuery($query); if ($this->db->loadResult()) { $query = "REPLACE INTO `#__kunenadiscuss`\n\t\t\t\t\tSELECT `content_id` , `thread_id`\n\t\t\t\t\tFROM `#__fb_discussbot`"; $this->db->setQuery($query); $this->db->query(); KunenaError::checkDatabaseError(); $this->debug("Migrated old data."); } } }
/** * Delete all rows by attributes * * @param array $conditions * * @return mixed */ public function deleteByAttributes(array $conditions) { $query = $this->db->getQuery(true); $where = array(); foreach ($conditions as $ckey => $cvalue) { $where[] = $this->quoteName($ckey) . ' = ' . (is_numeric($cvalue) ? intval($cvalue) : $this->quote($cvalue)); } $query->delete($this->quoteName($this->tableName)); $query->where($where); $this->db->setQuery($query); return $this->db->query(); }
public function toggle($id, $property) { $this->db->setQuery('SELECT `' . $property . '` FROM #__acctexp_' . $this->table . ' WHERE `id` = ' . $id); $newstate = $this->db->loadResult() ? 0 : 1; if ($property == 'default') { if (!$newstate) { echo !$newstate; return; } // Reset all other items $this->db->setQuery('UPDATE #__acctexp_' . $this->table . ' SET `' . $property . '` = ' . ($newstate ? 0 : 1) . ' WHERE `id` != ' . $id); $this->db->query(); } $this->db->setQuery('UPDATE #__acctexp_' . $this->table . ' SET `' . $property . '` = ' . $newstate . ' WHERE `id` = ' . $id); $this->db->query(); echo $newstate; }
/** * Execute the query * * @param string the query (optional, it will use the setQuery one otherwise) * @return mixed A database resource if successful, FALSE if not. */ function query($sql = null) { if ($sql !== null) { $this->setQuery($sql); } return $this->_db->query(); }