Thor
Thor

Reputation: 1202

PostgreSQL database converts my chars from perl to a weird format

I am having a problem when i update an entry in my postgresql database, it converts my charcters to the wrong format. The way I update is:

use Encode;
...
$user_name = escapeSql($user_name); # a statement that to doese this: line 1: $s =~ s/\?/_/g; and line 2: $s =~ s/\*/%/g;
$user_name = decode("utf-8", $user_name);
...
$statement = "UPDATE person SET name='".$user_name."', email='".$user_email."' WHERE id='".$user_id."'"; # The real statement have some more attributes, buts its the name that errors.
print STDERR "Statement: ". $statement;
$sth = $dbh->prepare($statement);
$result = $sth->execute();

As you see, I print out the statement to check the user_name looks like it should and here is what it looks like: enter image description here

As you can see its says "Thør Åstrüp Pédersen" which is my name where i have replaced some chars with the special chars im trying to insert/update my entry to. Now the big problem which i have been debugging for some days now, is when i make a select statement on the database and fetch my user_name to see if the new name (entered in a web-GUI using dojo) was changed and updated correctly.. but it looks like:

enter image description here

I simply cannot figure out why my database dose that or how i, in any way, could check what charcter encoding the database is set to and make the right conversion. But then again, it looks good in PERL since the error log outputs it correctly (as showen above in the first img), but the PostgreSQL database hates it and converts it for some reason to crappy chars.

I really hope someone can help, even though its not the first time i have met encoding problems.. but the first time I couldn't figure out since it looks like its a PostgreSQL thing and not Perl or PHP problem.

Upvotes: 0

Views: 312

Answers (1)

kworr
kworr

Reputation: 3674

You can check your database encoding via issuing \l in psql prompt. You can also check your client encoding with 'show client_encoding;'

It's maybe better to recreate database in UTF8. Everything about encodings in PostgreSQL is explained in the manual.

Upvotes: 2

Related Questions