**我正在使用PHP和SQL-SERVER ..我的连接字符串没问题,但是当我尝试取一些东西时,我们说(一列),当我print_r()
时,它只返回列名和数据,它显示符号。我也使用
以下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();
&GT;
*的 输出 *
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 :(得分:0)
看起来你在“NameOfStorage”字段中有二进制数据,你可以在推送JSON中的值之前使用base64_encode()函数进行编码,并查看数据是否在数组中打印。
答案 1 :(得分:0)
或许使用mb_convert_encoding()
很有用。 link