0

**我正在使用 PHP 和 SQL-SERVER .. 我的连接字符串没问题,但是当我尝试获取一些东西时,比如说(一列),当我print_r()只返回列名和数据时,它会显示符号。我还使用我正在使用的空值生成 JSON 输出

以下 php 脚本**

我的连接文件

<?php
    class odbcConnection
{
    public $myServer = "SMS-HP\MSSQL";
    public $myUser = "sa";
    public $myPass = "123456";
    public $myDB = "procurementdb";
    public $connDB;

    // function to connection to the database 
    public function connectionDB(){

        // check wheather the given function exists 
        if(function_exists(odbc_connect))
        {

            $this->connDB = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$this->myServer;Database=$this->myDB;", $this->myUser, $this->myPass);
            //echo("Connection Established <br>");
        }
        else
        {
            die("Connection Failed".odbc_errormsg());
        }

    }

    // function to closing the connection
    public function closeConnection()
    {
        odbc_close($this->connDB);
    }

}//End of class

//$conn = new odbcConnection();
//$conn->connectionDB();

  ?>

加载存储类文件

<?php
include("dbConnection.php");
class LoadStorageData extends odbcConnection
{
    public function LoadStorageData()
    {
        $this->connectionDB();
    }
    public function LoadData()
    {

        $sql ="select NameOfStorage from tblStaff where DivisionID=7 and DistrictID=1 order by NameOfStorage;";

        $result = odbc_exec($this->connDB,$sql);
        $dataSet = array();
        while($rows = odbc_fetch_array($result))
        {
            array_push($dataSet,$rows);
            echo("<pre>");
            print_r($rows);
            echo("</pre>");
        }

        if($dataSet){
            json_encode($dataSet);
            return json_encode($dataSet);
        }
        else{
            echo "error";
            return false;
        }

    }

}

$json = new LoadStorageData();
echo $json->LoadData();
$json->closeConnection();

?>

*输出*

Array
(
    [NameOfStorage] => þÎý
)

Array
(
    [NameOfStorage] => þÎ
)

Array
(
    [NameOfStorage] => þÎýÎ
)

Array
(
    [NameOfStorage] => þÎýÎ
)

Array
(
    [NameOfStorage] => þÎýÎ
)

Array
(
    [NameOfStorage] => þÎýÎ
)

Array
(
    [NameOfStorage] => þÎýÎ
)

[{"NameOfStorage":null},{"NameOfStorage":null},{"NameOfStorage":null},{"NameOfStorage":null},{"NameOfStorage":null},{"NameOfStorage":null},{"NameOfStorage":null}]

**对此的任何帮助表示赞赏....

谢谢 ....**

4

2 回答 2

0

也许使用mb_convert_encoding()是有用的。关联

于 2013-05-01T10:58:08.593 回答
0

似乎您在“NameOfStorage”字段中有二进制数据,您可以在将值推送到 JSON 之前使用 base64_encode() 函数进行编码,然后看看数据是否会打印到您的数组中。

于 2013-05-01T10:40:47.210 回答