+
+ //
+ // 'set names' or equivalents should be used only on post 2.3 FA versions
+ // otherwise text encoding can be broken during import
+ //
+ $encoding = null; // UI encoding for default site language is the default
+ $new_db = $init || db_fixed();
+ $new_file = count($set_names);
+ if ($new_db)
+ {
+ if ($new_file)
+ {
+ if (count($set_names)) // standard db restore
+ {
+ if (preg_match('/set\s*names\s*[\']?(\w*)[\']?/i', $set_names[0][0], $match))
+ $encoding = $match[1];
+ }
+ // otherwise use default site ui encoding
+ }
+ }
+ else
+ {
+ if ($new_file) // import on old db is forbidden: this would destroy db content unless latin1 was used before in UI
+ {
+ $msg = _("This is new format backup file which cannot be restored on database not migrated to utf8.");
+ if ($return_errors)
+ return $msg;
+ else
+ display_error($msg);
+ return false;
+ }
+ else // backup restore during upgrade failure
+ $encoding = 'latin1'; // standard encoding on mysql client
+ }
+
+ db_set_charset($db, $encoding);
+
+/*/ { // for debugging purposes