1

嗨,我正在尝试使用 php 从我的数据库中检索阿拉伯语数据,但我得到的只是问号.. 数据存储在数据库中,列类型是 nvarchar

我试图将此代码ini_set('mssql.charset', 'UTF-8'); 放在我的 php 中,但仍然无法正常工作

这是我的代码示例:db_connect.php:

<?php

ini_set('mssql.charset', 'UTF-8');

$link=mssql_connect('SQL*******', 'username', 'password');

?>

get_about.php

<?php

        include_once './db_connect.php';
        $sql ="SELECT * FROM About"; 
        $select = mssql_query($sql);

        if ($select) {
            while ($list = mssql_fetch_array($select)){
                $output = $list;
            }
            print json_encode($output);
        } else {
            print json_encode('fail select');
        }



?>
4

1 回答 1

0

Try this

<?php
$user = "user";
$pass = "Password";

//11.0 for SQL 2012,2014

$dsn = "Driver=SQL Server Native Client 11.0;Server=server.com;Port=1433;Database=database;";
$cx = odbc_connect($dsn,$user,$pass);

// Get the error message

if($cx === false) {
    throw new ErrorExcpetion(odbc_errormsg());
};
$resultset=odbc_exec($cx, "SELECT * FROM Table");


$json = array();

do {
     while ($row = odbc_fetch_array($resultset)) {
     $json[] = $row;
     }
} while ( odbc_next_result($resultset) );

/* Run the tabular results through json_encode() */
/* And ensure numbers don't get cast to trings */
echo json_encode($json);

odbc_close( $cx);

?>
于 2014-06-21T21:21:44.850 回答