2013-05-01 62 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

相关问题