$fields ) {
foreach ( (array) $fields as $field_type => $field_options ) {
dump("ALTER TABLE $table MODIFY $field_type $field_options;", $link_id);
}
}
foreach ( (array) $tables as $table )
dump("OPTIMIZE TABLE $table;", $link_id);
// Pogledamo, če je prišlo do kakšnih čudnih znakov in jih nadomestimo z pravimi
foreach($tables as $table) {
$result = mysql_query("SELECT * FROM $table", $link_id);
while( ($row = mysql_fetch_array($result, MYSQL_ASSOC)) !== false) {
convert($row, $table);
}
}
function convert($data, $table) {
$do_update = false;
foreach($data as $k => $value) {
if (!is_array($value)) {
$count = 0;
$data[$k] = str_replace(array('Ž', 'ž', 'Å¡', 'Å', 'ÄŒ', 'Ä'), array('Ž', 'ž', 'š', 'Š', 'Č', 'č'), $data[$k], $count);
if ($count > 0) {
$do_update = true;
}
}
}
if ($do_update === true) {
$query = createGenericUpdateSQL($data, $table, key($data), $data[key($data)]);
dump($query);
}
}
function createGenericUpdateSQL($values, $table, $where_field, $where_value){
$query = "UPDATE `$table` SET ";
$keys = array_keys($values);
$last_key = end($keys);;
foreach ($values as $key => $value){
$query .= "`$key` = '".$value."'";
if ($last_key != $key){
$query .= ', ';
}
}
$query .= " WHERE `$where_field`='".$where_value."' LIMIT 1;";
return $query;
}
function dump($data){
echo "$data\n";
}
?>