Error Writing to database with Greek chars

Error Writing to database with Greek chars

by Zisis Zisis -
Number of replies: 2

Hello,

i am using Moodle 2.0RC1 and i keep getting an error message "Error Writing to database" whenever i try to store something (a course name e.g.) in Greek.

It works like a charm for changes made in English....

Please help because it is essential smile.

 

 

The debugging gives me this :

"

Debug info: Incorrect string value: '\xCE\xA4\xCE\xAC\xCE\xBE...' for column 'name' at row 1
UPDATE mdl_course_categories SET name = ?,parent = ?,description = ?,descriptionformat = ? WHERE id=?
[array (
0 => 'Τάξεις/Μαθήματα',  /* GREEK CHARS */
1 => '0',
2 => '',
3 => '0',
4 => '1',
)]
Stack trace:
  • line 394 of /lib/dml/moodle_database.php: dml_write_exception thrown
  • line 922 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 954 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->update_record_raw()
  • line 94 of /course/editcategory.php: call to mysqli_native_moodle_database->update_record()

Thanks

Average of ratings: -
In reply to Zisis Zisis

Re: Error Writing to database with Greek chars

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hello,

I've just tried the Greek interface with the latest Moodle release available - Moodle 2.0 RC1 (Build: 20101110) - and there is no problem.

Are you certain that your moodle database was created with the correct utf8 parameter?

In reply to Joseph Rézeau

Απάντηση: Re: Error Writing to database with Greek chars

by Zisis Zisis -

OK

the error was at the db's collation.

thought that i had set default utf8_general_ci collation.

 

if anyone else has done same mistake here's the script that PRODUCES the sql queries required to change the database's encoding and collation . run it and then paste the produced queries in a phpmyadmin sql script window. ;)

////////////////////////////////////

//////////SCRIPT

/////////////////////////////////////

<?php
// Original script (v1.0) by/from: http://www.phpwact.org/php/i18n/utf-8/mysql
// Improved/modified (v1.05) by Bogdan http://bogdan.org.ua/
// Last updated: 2010-06-28
// this script will output all queries needed to change all fields/tables to a different collation
// it is HIGHLY suggested you make a MySQL backup prior to running any of the generated queries
// this code is provided AS IS and without any warranty
// add text/plain header when used not as a CLI script; PHP CLI SAPI shouldn't output headers
header("Content-Type: text/plain");
// precaution

set_time_limit(0);
// collation you want to change to:
$convert_to   = 'utf8_general_ci';
// character set of new collation:
$character_set= 'utf8';
// DB login information - *modify before use*
$username = 'evroglos_moodle2';
$password = 'lF.o$hzw8P](';
$database = 'evroglos_moodle2';
$host     = 'localhost';
//-- usually, there is nothing to modify below this line --//
// show TABLE alteration queries?
$show_alter_table = true;
// show FIELD alteration queries?
$show_alter_field = true;
mysql_connect($host, $username, $password);
mysql_select_db($database);
$rs_tables = mysql_query(" SHOW TABLES ") or die(mysql_error());
while ($row_tables = mysql_fetch_row($rs_tables)) {
$table = mysql_real_escape_string($row_tables[0]);
// Alter table collation
// ALTER TABLE `account` DEFAULT CHARACTER SET utf8
if ($show_alter_table)
echo("ALTER TABLE `$table` DEFAULT CHARACTER SET $character_set;\n");
$rs = mysql_query(" SHOW FULL FIELDS FROM `$table` ") or die(mysql_error());
while ( $row = mysql_fetch_assoc($rs) ) {
if ( $row['Collation'] == '' || $row['Collation'] == $convert_to )
continue;
// Is the field allowed to be null?
if ( $row['Null'] == 'YES' )
$nullable = ' NULL ';
else
$nullable = ' NOT NULL ';
// Does the field default to null, a string, or nothing?
if ( $row['Default'] === NULL && $row['Null'] == 'YES' )
$default = " DEFAULT NULL ";
elseif ( $row['Default'] != '' )
$default = " DEFAULT '".mysql_real_escape_string($row['Default'])."'";
else
$default = '';
// sanity check and fix:
if ($nullable == ' NOT NULL ' && $default == ' DEFAULT NULL ') {
$default = '';
echo "/* Warning: wrong combination of 'default value' and 'NULL-flag' detected - and fixed! */\n";
echo "/* Diagnostics: row[Null] = '$row[Null]', row[Default] = " . mysql_real_escape_string($row['Default']) . ", MySQL version: " . mysql_get_server_info() . " */\n";
}
// Don't alter INT columns: no collations, and altering them drops autoincrement values
if (strpos($row['Type'], 'int') !== false) {
$show_alter_field = False;
}
else {
$show_alter_field = True;
}
// Alter field collation:
// ALTER TABLE `tab` CHANGE `field` `field` CHAR( 5 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL
if ($show_alter_field) {
$field = mysql_real_escape_string($row['Field']);
echo "ALTER TABLE `$table` CHANGE `$field` `$field` $row[Type] CHARACTER SET $character_set COLLATE $convert_to $nullable $default;\n";
}
}
}
?>

 

 

//////////////////////////////////////////

//////////////END OF SCRIPT

/////////////////////////