Encoding is not proper when query from PHP script

Moderator: NorbertKrupa

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: Encoding is not proper when query from PHP script

Post by id10t » Thu Jul 25, 2013 1:12 pm

Hi!

Lets compare other params:

vertica

Code: Select all

daniel@synapse:~$ dpkg -s vertica
...
Version: 6.1.2-0
Provides: vertica-base
Depends: bc, sudo, openssh-client, openssh-server, locales
unixODBC:

Code: Select all

daniel@synapse:~$ dpkg -s unixODBC
...
Version: 2.2.14p2-5ubuntu4
Depends: libc6 (>= 2.14), libreadline6 (>= 6.0), odbcinst1debian2 (>= 2.2.11-3), libodbc1 (>= 2.2.14p2-3)
php

Code: Select all

daniel@synapse:~$ dpkg -s php5
...
Version: 5.4.6-1ubuntu1.3
Depends: libapache2-mod-php5 (>= 5.4.6-1ubuntu1.3) | libapache2-mod-php5filter (>= 5.4.6-1ubuntu1.3) | php5-cgi (>= 5.4.6-1ubuntu1.3) | php5-fpm (>= 5.4.6-1ubuntu1.3), php5-common (>= 5.4.6-1ubuntu1.3)

SiliconCraftsman
Newbie
Newbie
Posts: 8
Joined: Wed Jul 24, 2013 11:25 am

Re: Encoding is not proper when query from PHP script

Post by SiliconCraftsman » Thu Jul 25, 2013 1:31 pm

All the same but php
I have php 5.3.10
I'll try to upgrade it

SiliconCraftsman
Newbie
Newbie
Posts: 8
Joined: Wed Jul 24, 2013 11:25 am

Re: Encoding is not proper when query from PHP script

Post by SiliconCraftsman » Thu Aug 01, 2013 5:00 am

In php 5.4.x same result
I found that this problem occurs only when you run a script from the web (web server is Apache2)
So if you run the script from the console, it's OK
But if you do it from localhost/test.php, we get the issue
It occurs on x32 and x64 versions of drivers for Linux and Windows
How does the Apache can influence the outcome results that we get from Vertica?

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: Encoding is not proper when query from PHP script

Post by id10t » Thu Aug 01, 2013 7:39 am

Hi!

How to change the default encoding to UTF-8 for server >> http://stackoverflow.com/questions/9138 ... for-server

SiliconCraftsman
Newbie
Newbie
Posts: 8
Joined: Wed Jul 24, 2013 11:25 am

Re: Encoding is not proper when query from PHP script

Post by SiliconCraftsman » Thu Aug 01, 2013 9:50 am

Encoding for server is already UTF-8
Locale for server is en_US.UTF-8

Any ideas?

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: Encoding is not proper when query from PHP script

Post by id10t » Thu Aug 01, 2013 11:04 am

Hi!

You need to provide more info about yours system configuration.
---

1. Check that data in UTF-8 without BOM

2. for PHP Config (for me /etc/php5/cli/php.ini)
PHP should have multi-byte support built-in.

Code: Select all

default_charset = "utf-8"
mbstring.internal_encoding=utf-8
mbstring.http_output=UTF-8
mbstring.encoding_translation=On
mbstring.func_overload=6
in php-scripts (without global config in php.ini):
Assuming you have multi-byte support built-in, now you need to make sure PHP knows that you want to handle text as UTF-8 internally. Add the following to an include that gets parsed before anything else, and you should be good to go:

Code: Select all

//setup php for working with Unicode data
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
mb_http_input('UTF-8');
mb_language('uni');
mb_regex_encoding('UTF-8');
ob_start('mb_output_handler');
3. for HTML page:

Code: Select all

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4. for XML

Code: Select all

<? xml version="1.0" encoding="utf-8" ?>

SiliconCraftsman
Newbie
Newbie
Posts: 8
Joined: Wed Jul 24, 2013 11:25 am

Re: Encoding is not proper when query from PHP script

Post by SiliconCraftsman » Mon Aug 05, 2013 3:15 pm

Needs to added locale setting directly to PHP code and everything start to work

Code: Select all

setlocale(LC_ALL, 'en_US.UTF-8');

Post Reply

Return to “Vertica Database Development”