Vertica ODBC charset Windows VS Linux

We're having a bit of trouble developing our PHP application using Vertica. Since an image is worth a thousand words, let's say we have the current code:

if(PHP_OS == "Linux")
    $c = new PDOVertica("Driver=/opt/vertica/lib64/;Server=;Port=5433;Database=flexgroup;", "user", "password");
    $c = new PDOVertica("Driver=Vertica;Server=;Port=5433;Database=flexgroup;Server_CSet=UTF-8", "user", "password");

$sql = "SELECT NoClient, NomClient FROM tblclients ORDER BY NomClient";

$stmt = $c -> prepare( $sql );
$stmt -> execute();

while($res = $stmt -> fetch(PDO::FETCH_ASSOC))
    echo $res['NomClient'];

This straightforward piece of code works and outputs the name of our clients almost correctly (if anyone's curious, the PDOVertica class is a homemade wrapper we built to bypass a bug where PDO loses parameter values. It calls the corresponding ODBC functions).

Anyway, the problem comes with accented characters. In order to output them correctly on our development machines, which run windows, we have to do the following

echo utf8_encode($res['NomClient']);

Now this wouldn't be a problem if both production and development environments worked the same way... but of course, they don't. In production, using utf8_encode garbles the string and we instead have to do this for the same string to come out correctly:

echo $res['NomClient'];

The problem here is that our development environment is Windows and the production servers are Linux. We're suspecting the driver detects the OS on which it's installed and does silent conversions, which explains why we need to wrap the calls in Windows and not in Linux. The question is then... is there a way to prevent that and always have results in UTF8?

Thanks in advance,



  • Well, it turns out I was right about the automatic conversion. A bit of testing revealed that the string my application receives from Vertica is actually encoded in UTF-16 when in Windows and in UTF-8 when in Linux, thus my display problems. Is there a parameter I can set in the connection string to avoid this conversion?

    Thanks in advance

    P.S. Corrected my original encoding. It turns out ISO-8859-1 and UTF-16 intersect as far as letters and numbers are concerned, which is why I made this mistake. Anyway, sorry for this slight confusion.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file