ho sviluppato uno script PHP che dovrebbe connettersi a un sistema di database pervasivo:Come impostare la codifica per il database pervasivo via ODBC in PHP?
$connection_string = "Driver={Pervasive ODBC Client Interface};ServerName=127.0.0.1;[email protected]";
$conn = odbc_connect($connection_string,"administrator","password");
Se eseguo una query, i dati di ritorno non è UTF8. mb_detect_encoding
mi dice che la codifica è ASCII. Ho provato a convertire i dati tramite iconv
, ma non funziona. Così ho provato qualcosa di simile a modificare la codifica dopo che lo script collegato:
odbc_exec($conn, "SET NAMES 'UTF8'");
odbc_exec($conn, "SET client_encoding='UTF-8'");
Ma niente aiuta! Qualcuno può aiutarmi? Grazie.
------------------------------ modifica --------------- ----------------
ecco lo script completo, perché non funziona niente finora:
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;[email protected];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"]));
}
}
il log del server dice il 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 per una, ma dovrebbe essere SS (personaggio tedesco)
\ XE1 stand per una, ma dovrebbe essere ß (personaggio tedesco)
grazie mille! Alla fine ho cambiato il seguente e funziona: $ connection_string = "Driver = {Pervasive Client Interface ODBC}; ServerName = 127.0.0.1; dbq = @ test; Client_CSet = UTF-8; Server_CSet = CP850"; e iconv ("CP850", "UTF-8", $ row ["campo"]) –