**我使用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}]
**有這方面的幫助表示讚賞....
感謝.... **