Hello,
Iam reading from MSSQL chinese database, my website is UTF-8.
I just need to represent data, data stored in the database is in Arabic Letters, Actually when i login to Server and browse data there … it’s shown PERFECT !
but when i try to read from another server, it comes ??? question marks !
the current collation for the db is Chinese_Taiwan_Stroke_CI_AS
public function connect_225()
{
$conn = mssql_connect("server", "user", "password" );
if (!$conn)
die("Error connecting to SQL: " . mssql_get_last_message ());
mssql_select_db("dbname", $conn);
return $conn;
}
public static function getROMCharacters($userName) {
//$dbConn = self::connect_31();
$dbConn = self::connect_225();
//mssql_query("set ANSI_NULLS ON");
//mssql_query("set ANSI_WARNINGS ON");
$sqlQuery = "SELECT RoleName FROM RoleData
WHERE Account_ID = '$userName' and isDelete <> 1";
//mssql_query("SET NAMES 'utf8'", $dbConn);
//mssql_query("SET CHARACTER SET UTF8", $dbConn);
$result = mssql_query($sqlQuery, $dbConn);
$charArray = array();
while ($row = mssql_fetch_row($result) ) {
//$charName = trim(iconv('BIG5', 'UTF-8', $row[0]));
//$charName = trim(utf8_encode($row[0]));
//$charName = mysql_real_escape_string($row[0]);
//$charName = mb_convert_encoding($charName,"UTF-8","BIG-5");
$charName = self::convToUtf8($row[0]);
$charArray[] = $charName;
}
//print_r($charArray);
//die();
return $charArray;
}
I have been trying those functions :
function convToUtf8($str)
{
if( mb_detect_encoding($str,"UTF-8, ISO-8859-1, GBK")!="UTF-8" )
{
return iconv("gbk","utf-8",$str);
}
else
{
return $str;
}
}
AND :
public static function big52utf8($big5str) {
$blen = strlen($big5str);
$utf8str = "";
for($i=0; $i<$blen; $i++) {
$sbit = ord(substr($big5str, $i, 1));
//echo $sbit;
//echo "<br>";
if ($sbit < 129) {
$utf8str.=substr($big5str,$i,1);
}elseif ($sbit > 128 && $sbit < 255) {
$new_word = iconv("BIG5", "UTF-8", substr($big5str,$i,2));
$utf8str.=($new_word=="")?"?":$new_word;
$i++;
}
}
return $utf8str;
}
and actually, nothing worked !
So, when i tried :
mssql_query(“SET NAMES ‘utf8’”, $dbConn);
it shows error ! i dont know if MSSQL doesnt support " SET NAMES " or what !
Also, Iam not sure if it’s Big5 or not !! db collation at server is " Chinese_Taiwan_Stroke_CI_AS ".
any ideas, iam stuck over here