Invalid string identifier error in user's account page

Invalid string identifier error in user's account page

by Albert R. -
Number of replies: 8

I'm using Moodle 2.2.3 with the external database authentication plugin and the external database enrollment plugin.

It all seems to work fine so far, but one thing. After logging in with a user obtained from the external database, when I click the username on the top right of the screen to access the user account, I get the following error:

Codification error detected, must be fixed by a programmer: Invalid string identifier. Most probably some illegal character is part of the string identifier. Please fix your get_string() call and string definition

If I log in with a user that doesn't come from the external database (i.e. the admin user) I don't get any errors.

I believe I've set the codification option (utf-8) correctly in both plugins when configuring them. Besides, I'm looking in the mdl_user table in Moodle's database and I don't see any weird characters in any of the fields. One thing that might be causeing this is that the external database encoding is UTF-8, but the fields of the users table in that database that store any characters have the latin1_swedish_ci collation. The problem is that I already tried setting the enconding in the plugins settings as latin1_swedish_ci, but then the authentication doesn't work (it works if I leave it to UTF-8, like I have it now).

Any ideas on how I can fix this issue?

Average of ratings: -
In reply to Albert R.

Re: Invalid string identifier error in user's account page

by Guillermo Madero -

Hi Albert,

Have you tried changing (after making a backup, of course) the collation of the fields of the external DB?

In reply to Guillermo Madero

Re: Invalid string identifier error in user's account page

by Albert R. -

Hi Guillermo,

 

Thank you for your reply. Do you mean to change the collation to UTF-8 in those fields? If there's no other option I could try that, only that the external database (and all those user records) is already being used by some other websites, so I would prefer not to mess with that unless there's no other option...

In reply to Albert R.

Re: Invalid string identifier error in user's account page

by Guillermo Madero -

Hi Albert,

Yes, I mean changing the collation of those fields to utf8_general_ci or utf8_unicode_ci (depending on which one is being used on your Moodle DB).

In general terms, changing the collation should be a safe procedure as data itself is not modified (at most, only indexes would need to be rewritten, and only if the field in question is part of an index). Collation just interprets the binary data stored: it "does NOT change the 'storage', only the actions performed by ORDER BY, etc.".

Put your site in maintenance mode, backup all the related databases before changing the collation, do the change and test everything.

Thinking about other possible solutions... ¿how viable would it be to use an independent external db for your Moodle site (or even work without one)? Maybe you could have a synchronization script moving data from your external DB into the secondary external one. This way you wouldn't need to risk the operation of your other sites.

In reply to Guillermo Madero

Re: Invalid string identifier error in user's account page

by Jeffrey Jones -

Guillermo:
       Could you clarify? I'm also getting the exact same error. I have full root access to our MySQL 5.1 database. We have just finished an upgrade of a major Moodle install from 1.9.17+ to 2.2.3. In order to induce the upgrade to run, I converted all database collations from utf8_general_ci to utf8_unicode_ci. It's only the administration/users/browse... which is broken.  Everything else seems to be working (at least so far -- we just went live with the upgrade today!).
       It seems obvious it's an artifact of the upgrade, since we did a clean, new install of 2.2.3 and the user account browsing there works. I compared data structure between the two mdl_user tables, and the collation is identical, both for the table and all fields which hold data. We also ran a schema check against the upgraded data, making changes to its schema to match a clean new install...no help.
       Any ideas?

In reply to Jeffrey Jones

Re: Invalid string identifier error in user's account page

by Guillermo Madero -

Hi Jeffrey,

Moodle works with both, general and unicode utf8 collations. So why did you need to change from one to the other?

At my following post I left some instructions on how to check the collation definitions.

Anyway, if both mdl_user tables have exactly the same structure then the problem must reside in the data itself. Maybe you could try dumping your upgraded DB, restore the backup file into the clean DB and go to the user>browse page of the clean installation to see if it works.

In reply to Jeffrey Jones

Re: Invalid string identifier error in user's account page

by Jeffrey Jones -
In reply to Jeffrey Jones

Re: Invalid string identifier error in user's account page

by Albert R. -

So following the idea that's mentioned in the post that Jeffrey linked, I took a look at the "country" field of the users table. Moodle saves the country with character (i.e. US), but the external database that I'm using has its own code (each country has a number asigned, i.e. the USA is #7).

I had set up the "country" field in the moodle DB to get its value from the "country" field of the external database, so for the user coming from this external DB, the "country" field had a value of "7" instead of "US".

So I went into the users table of the Moodle DB and manually changed the "7" for "US" and voilà! I don't get the error anymore!

So I guess Moodle didn't like finding a number instead of whatever alphabetical code in the "country" field. What I've done now is to stop getting that field's value from the external database, since it's really not that important for us, and hopefully when new users log in this won't cause any issue anymore.

My question would be, what if I really wanted to import that field? Is it just not possible since both databases use a different code system to identify countries? Is there any way I could "parse" those number into alphabetical codes when Moodle is creating a new user account?

Thank you for your help!!!