Cyrillic characters in database Cyrillic characters in database
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Cyrillic characters in database

Started by sard, June 05, 2009, 02:43:39 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

sard

Hi,
Becuase my native language is one of Cyrillic group of languages, albums, categories, and some files are writtein with cyrillic charset. Their view (utf-8) in browser is ok, but in database even utf-8 is selected they are unreadable. If i write them in database with cyrillic letters then opposite they become unreadable in browser show of the gallery. Can you tell me how to show the both sides, databes and gallery in browser with proper cyrillic charset.

Thank you

Joachim Müller

#1
Use cyrillic or unicode collation for your database as well. Not sure what you mean: how do you access the database? You'll need a tool that makes sure that the database content doesn't display "garbled", as you can't directly look at the database.

sard

I use phpmyadmin. All charset through phpmyadmin are set to utf8_unicode_ci. Still everything cyrillic is unreadable (nonmeaningfull). If i write them in cyrillic then they stay ok, but opposite they become unreadable (nonmeaningfull) in gallery (browser) with the same supstitute characters.


Jaguar13

I have same problems with the Russian language :(

If I put the Russian text using coppermine interface, I am getting database records in phpmyadmin looks like you are viewing UTF-8 using CP1251 codepage. I.e. if I type "Галерея улик e-mafia", I am getting "Р"алерея улик e-mafia" in the phpmyadmin. If I change value in the phpmyadmin, I am getting like "������� ���� e-mafia" in the coppermine.

MySQL charset:  UTF-8 Unicode (utf8)
MySQL connection collation: utf8_unicode_ci

The same problem I am getting the trying to bridge coppermine to phpBB 2.0.18, all users, who have Russian names displayed with ���� characters in Coppermine :(.

Jaguar13

Sorry forget to add information about mysql and phpmyadmin versions:

Server version: 4.1.22-log
MySQL client version: 4.1.22
phpMyAdmin - 2.11.9.5
Used PHP extensions: mysql

Joachim Müller


Jaguar13

I found the reason of this:
Looks like webhoster set up mysql to get out data by default in the CP1251 encoding. I.e. character_set_client='cp1251', character_set_results='cp1251', character_set_connection='cp1251'.

I solve this problem by adding "SET NAMES 'utf8'" query to the cpg_db_connect function in functions.inc.php

function cpg_db_connect()
{
        global $CONFIG;
        $result = @mysql_connect($CONFIG['dbserver'], $CONFIG['dbuser'], $CONFIG['dbpass']);
        if (!$result) {
                return false;
        }
        if (!mysql_select_db($CONFIG['dbname']))
                return false;
        mysql_query("SET NAMES 'utf8'", $result);
        return $result;
}


I think instead of 'utf8', i should put the variable, responsible in Coppermine for Character encoding.
But I don't know it's name, and looks like it is stored in database, so results might be unpredictable.

Old RMN

Jaguar13, your solution is totally amazing and helped me resolve a long, long search.

Hint for all phpmyadmin users stuck with charset display problems who already have checked the collation settings of their own database and its tables:

This hack does not only apply to Cyrillic characters and not only to your particular provider.

Thank you very much!
Sometimes to find the way home one has to leave it.

Joachim Müller

Quote from: Jaguar13 on June 13, 2009, 12:32:07 AMI think instead of 'utf8', i should put the variable, responsible in Coppermine for Character encoding.
But I don't know it's name, and looks like it is stored in database, so results might be unpredictable.
The variable is $CONFIG['charset']
However, I can see another issue: I'm not sure that all webhosted users will have permission on database level to perform the SET NAMES query.

@devs: do you think that this should be added to the core? What happens if a user doesn't have permission to execute that query?

sard


Joachim Müller