我将PHP连接到MSSQL而不是MySQL。 PHP在我的PC上的nginx Web服务器上运行。我已经成功连接到数据库,并能够在php中显示获取的数据,但它显示404未找到哪个是奇怪的。
here is the screenshot of the result
这是我的代码,但即使我把phpinfo(),它仍然会显示404未找到但会显示php的信息。
<?php
class Mssql{
private $_database = "sample";
private $_host = "CSRMS-SVR-DB1\CSOFFICE9";
private $_username ="sa";
private $_password ="_pass123";
public $con;
public function mssql_connect(){
$con_properties = [
"Database" => $this->_database,
"UID" => $this->_username,
"PWD" => $this->_password
];
$this->con = sqlsrv_connect($this->_host, $con_properties);
if ($this->con) {
echo "Connection Success";
}
else {
die( print_r( sqlsrv_errors(), true ));
}
}
}
$sql = "SELECT * FROM prof";
$test = new Mssql;
$test->mssql_connect();
$result = sqlsrv_query($test->con, $sql);
$row = sqlsrv_fetch_array($result);
$someJSON = json_encode($row);
echo $someJSON;
&GT;