PHP PDO SQL查询别名为UTF-8

时间:2018-02-22 16:03:00

标签: php pdo adodb sqlsrv

我正在尝试将别名表作为UTF-8,在一个简单的选择查询中,但我在别名列名称中得到了胡言乱语。

这是我的代码:

include("adodb5/adodb.inc.php"); 
//create an instance of the  ADO connection object
$conn =&ADONewConnection ('sqlsrv');
//define connection string, specify database driver
$conn->Connect('xxx.xxx.x.xxx:1400', 'user', 'password', 'DbName');
//declare the SQL statement that will query the database
$query = "select firstName as 'שם פרטי' from users";
$rs = $conn->execute($query);
//execute the SQL statement and return records
$arr = $rs->GetArray();
print_r($arr);

这是我的结果:

Array
(
    [0] => Array
        (
            [�� ����] => יעקב
            [0] => יעקב
        )
)

结果为UTF-8,但我无法获得UTF-8中列的别名。

任何想法?

1 个答案:

答案 0 :(得分:-1)

您可以在连接字符串中添加UTF-8解码,如:

$dbConn = new PDO('mysql:host=localhost;dbname=' . $dbname . ';charset=UTF8', 
$username, $password);