/** * Builds an INSERT/REPLACE query * * @param string The system's table prefix * @param string The name of the database table to be affected (do not include TABLE_PREFIX in your argument) * @param bool Perform REPLACE INTO instead of INSERT * @param bool Perform INSERT IGNORE instead of INSERT * * @return string SQL Insert query */ function fetch_insert_sql($tableprefix, $table, $replace = false, $ignore = false) { $sql = ($replace ? "REPLACE" : ($ignore ? "INSERT IGNORE" : "INSERT")) . " INTO {$tableprefix}{$table}\r\n\t(" . implode(', ', array_keys($this->{$table})) . ")\r\nVALUES\r\n\t("; foreach ($this->{$table} as $fieldname => $value) { if (isset($this->bitfields["{$fieldname}"])) { $bits = 0; foreach ($value as $bitvalue => $bool) { $bits += $bool ? $bitvalue : 0; } $value = $bits; } $sql .= (isset($this->rawfields["{$fieldname}"]) ? $value === NULL ? 'NULL' : $value : $this->dbobject->sql_prepare($value)) . ', '; } $sql = substr($sql, 0, -2); $sql .= ')'; return $sql; }