With PHP, I am trying to read data from Pervasive DB v9.5 and insert it to PostgreSQL 9.3 (encoding: UTF-8) on Windows 2008. I did not choose or code PervasiveDB (I am just reading data from it). With ODBC I read data from Pervasive and write it to console with no problem. However when I try to insert it to Postgre I encounter with
Warning: pg_execute(): Query failed: ERROR: invalid byte sequence for encoding "UTF8": 0x94 in file.php on line ..
So, I saw that Postgres did not like the string I gave.
Then I use
var_dump(iconv_get_encoding('all'));
and see that my encoding is ISO-8859-1
and modify the string with
iconv ( 'ISO-8859-1' , 'UTF-8' , $a)
Now, the error is gone. However the string which reached to Postgres is not correct.
The code I used is below. And my test string is aöaçaşaıağaüaÖaÇaŞaİaĞaÜ
$a is the string which comes from Pervasive
echo $a;
gives aöaçaşaıağaüaÖaÇaŞaİaĞaÜ
echo iconv ( 'ISO-8859-1' , 'UTF-8' , $a)
gives a┬öa┬ça┬şa┬ıa┬ğa┬üa┬Öa┬Ça┬Şa┬İa┬Ğa┬Ü
<?php
//var_dump(iconv_get_encoding('all'));
$conn = pg_connect("host=localhost port=5432 dbname=xxx user=xxx password=".$argv[1]);
$result = pg_prepare($conn, "my_query", 'SELECT * FROM func_my_deneme($1)');
$connect_string = "DRIVER={Pervasive ODBC Client Interface}; SERVERNAME=localhost; SERVERDSN=xxx;";
$pervasiveconn = odbc_connect($connect_string, 'xxx', 'xxx');
$pervasive_result = odbc_exec($pervasiveconn ,"SELECT something");
while(odbc_fetch_row($pervasive_result)){
$a=odbc_result($pervasive_result,1);
echo $a;
$result = pg_execute($conn, "my_query", array(iconv ( 'ISO-8859-1' , 'UTF-8' , $a)));
}
?>