2013-05-01 61 views
0

**我使用PHP和SQL-SERVER預期的數據..我的連接字符串是好的,但是當我嘗試獲取一些假設(一列),當我print_r()返回單純的列名和在數據中,它顯示符號。此外,我產生空值我使用的不能得到什麼,我

以下PHP腳本的JSON輸出**

我的連接文件

<?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}] 

**有這方面的幫助表示讚賞....

感謝.... **

回答

0

好像你有二進制數據在「NameOfStorage」字段中,可以使用base64_encode()函數進行編碼,然後再在JSON中推送值,並查看數據是否在您的數組中打印。

0

可能使用mb_convert_encoding()是非常有用的。 link

相關問題