Quantcast
Channel: Microsoft Drivers for PHP for SQL Server forum
Viewing all articles
Browse latest Browse all 163

How to catch multi language's data in MSSQL and data isn't garbled

$
0
0

Hi everyone, I'm Taiwanese PHP developer, sorry for my poor English.

I have 3 language's data:Simplified Chinese,Traditional Chinese, and English in our mssql2012 database.

If I want to use ADODB to catch data,The Simplified Chinese and Traditional Chinese will be garbled.

I try to use mb_convert_encoding($data,'UTF-8','BIG-5'), the Traditional Chinese is ok, but Simplified Chinese is still garbled.

Do anyone have suggestion?

This is my output:

Array
(
    [0] => Array
        (
            [0] => ZHS2
            [1] => ?体中文
            [2] => 123
        )

    [1] => Array
        (
            [0] => ZHS3
            [1] => 翻?
            [2] => 123
        )

    [2] => Array
        (
            [0] => ZHS
            [1] => ?体中文
            [2] => Chinese Simplified
        )

    [3] => Array
        (
            [0] => ZHT
            [1] => 繁體中文
            [2] => Chinese Traditional
        )

    [4] => Array
        (
            [0] => US
            [1] => English
            [2] => English US
        )

)

Here is my code:

<?php
include('adodb5/adodb.inc.php');

	function encoding_data($results){
		foreach($results as $key1 => $result){
			foreach ($result as $key2 => $arr_str){
				if(is_integer($key2)){
					//unset($results[$key1][$key2]);
					//echo $key2."=>".$arr_str."<p />";
				}else{
					//echo $key2."=>".$arr_str."<p />";
					$results[$key1][$key2] = mb_convert_encoding($arr_str, 'UTF-8','BIG-5');
				}
				$results[$key1][$key2] = mb_convert_encoding($arr_str, 'UTF-8', 'BIG-5');
			}
		}
		return $results;
	}

	$sql = $_REQUEST['sql'];
	$usedb = $_REQUEST['usedb'];

	if($sql==""){

		$sql = "select * from HCP";

	}

	if($usedb == ""){

		$usedb ="oci8";

	}

	if($usedb == "mssql"){

		$hostname = "Driver={SQL Server};Server=XXXX,XXXX;Database=XXXX;CharacterSet=UTF-8;UID=XXXX;PWD=XXXX";
		//$port = XXXX;
		$dbname = "XXXX";
		$username = "XXXX";
		$pw = "XXXX";

		$mssqlconn = &ADONewConnection ('odbc_mssql');
		//define connection string, specify database driver
		$mssqlconn->Connect($hostname, $username, $pw , $dbname);
		$mssqlconn->debug = false;

		$results = $mssqlconn->GetArray($sql);
		$results = encoding_data($results);

		echo "<pre>",print_r($results),"</pre>";
		print_r($usedb);
?>



Viewing all articles
Browse latest Browse all 163

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>