I developed a PHP script which should connect to a pervasive database system:
$connection_string = "Driver={Pervasive ODBC Client Interface};ServerName=127.0.0.1;dbq=@test";
$conn = odbc_connect($connection_string,"administrator","password");
If I execute a query, the returning data is not UTF8. mb_detect_encoding
tells me, the encoding is ASCII. I tried to convert the data via iconv
, but it doesn't work. So i tried something like that to change the encoding after the script connected:
odbc_exec($conn, "SET NAMES 'UTF8'");
odbc_exec($conn, "SET client_encoding='UTF-8'");
But nothing helps! Can anyone help me? Thanks.
------------------------------ edit -------------------------------
here is the complete script, because nothing works so far:
class api {
function doRequest($Url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
$output = curl_exec($ch);
curl_close($ch);
}
}
$connection_string = "Driver={Pervasive ODBC Client Interface};ServerName=127.0.0.1;dbq=@test;Client_CSet=UTF-8;Server_CSet=UTF-8";
$conn = odbc_connect($connection_string,"administrator","xxx");
if ($conn) {
$sql = "SELECT field FROM table where primaryid = 102";
$cols = odbc_exec($conn, $sql);
while( $row = odbc_fetch_array($cols) ) {
$api = new api();
// --- 1 ---
$api->doRequest("http://example.de/api.html?value=" . @urlencode($row["field"]));
// --- 2 ---
$api->doRequest("http://example.de/api.html?value=" . $row["field"]);
// --- 3 ---
$api->doRequest("http://example.de/api.html?value=" . utf8_decode($row["field"]));
}
}
The server log says the follwing:
--- 1 --- [24/May/2016:14:05:07 +0200] "GET /api.html?value=Talstra%E1e+7++++++++++++++++++++++++++++++++++++++++++++++++ HTTP/1.1" 200 93 "http://www.example.org/yay.htm" "MozillaXYZ/1.0"
--- 2 --- [24/May/2016:11:31:10 +0200] "GET /api.html?value=Talstra\xe1e 7 HTTP/1.1" 200 83 "http://www.example.org/yay.htm" "MozillaXYZ/1.0"
--- 3 --- [24/May/2016:14:05:07 +0200] "GET /api.html?value=Talstra?e 7 HTTP/1.1" 200 93 "http://www.example.org/yay.htm" "MozillaXYZ/1.0"
%E1 stand for á, but it should be ß (german character)
\xe1 stand for á, but it should be ß (german character)