/** * Assign a value to 1 field for tickets matching a set of conditions * * @param string $fieldname * @param string $fieldvalue * @param object $criteria {@link CriteriaElement} * * @return bool FALSE if update failed * @access public */ public function updateAll($fieldname, $fieldvalue, $criteria = null) { $set_clause = is_numeric($fieldvalue) ? $fieldname . ' = ' . $fieldvalue : $fieldname . ' = ' . $this->_db->quoteString($fieldvalue); $sql = 'UPDATE ' . $this->_db->prefix($this->_dbtable) . ' SET ' . $set_clause; if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { $sql .= ' ' . $criteria->renderWhere(); } if (!($result = $this->_db->query($sql))) { return false; } return true; }
/** * @param XoopsDatabase $db * @param $table * @param $field * @param string $condition * * @return bool */ function getDbValue(XoopsDatabase $db, $table, $field, $condition = '') { $table = $db->prefix($table); $sql = "SELECT `{$field}` FROM `{$table}`"; if ($condition) { $sql .= " WHERE {$condition}"; } $result = $db->query($sql); if ($result) { $row = $db->fetchRow($result); if ($row) { return $row[0]; } } return false; }
/** * This method allows to copy fields from one table to another * * @param array $fieldsMap Map of the fields * ex: array('oldfieldname' => 'newfieldname'); * @param string $oTableName Old Table * @param string $nTableName New Table * @param bool $dropTable Drop old Table * * @return this does not return anything */ public function copyFields($fieldsMap, $oTableName, $nTableName, $dropTable = false) { $sql = "SHOW COLUMNS FROM " . $this->db->prefix($oTableName); $result = $this->db->queryF($sql); if (($rows = $this->db->getRowsNum($result)) == count($fieldsMap)) { $sql = "SELECT * FROM " . $this->db->prefix($oTableName); $result = $this->db->queryF($sql); while ($myrow = $this->db->fetchArray($result)) { ksort($fieldsMap); ksort($myrow); $sql = "INSERT INTO `" . $this->db->prefix($nTableName) . "` " . "(`" . implode("`,`", $fieldsMap) . "`)" . " VALUES ('" . implode("','", $myrow) . "')"; $this->db->queryF($sql); } if ($dropTable) { $sql = "DROP TABLE " . $this->db->prefix($oTableName); $this->db->queryF($sql); } } }
/** * Load table schema from database, or starts new empty schema if * table doesn't exist * * @param string $table table * * @return bool true if no errors, false if errors encountered */ public function addTable($table) { if (isset($this->tables[$table])) { return true; } $tableDef = $this->getTable($table); if (is_array($tableDef)) { $this->tables[$table] = $tableDef; return true; } else { if ($tableDef === true) { $tableDef = array(); $tableDef = array('name' => $this->db->prefix($table), 'options' => 'ENGINE=MyISAM'); $tableDef['create'] = true; $this->tables[$table] = $tableDef; $this->queue[] = array('createtable' => $table); return true; } else { return false; } } }
/** * Return a table name, prefixed with site table prefix * * @param string $table table name to contain prefix * * @return string table name with prefix */ protected function name($table) { return $this->db->prefix($table); }