通过Php从MsSql Server获取数据

时间:2017-05-12 08:56:13

标签: php sql-server

我正在尝试从mssql服务器获取数据但是当我运行代码浏览器showw白色空白屏幕时。连接&查询是文件中的一个,它托管在正常的网站托管上。

$hostname = "servername";
$username = "username";
$password = "password";
$dbName = "dbname";

MSSQL_CONNECT($hostname,$username,$password) or DIE("DATABASE FAILED TO RESPOND.");
mssql_select_db($dbName) or DIE("Database unavailable");

2 个答案:

答案 0 :(得分:0)

$hostname = "servername";
$username = "username";
$password = "password";
$dbName = "dbname";

$conn = MYSQL_CONNECT($hostname,$username,$password) or DIE("DATABASE FAILED TO RESPOND.");
mysql_select_db($dbName) or DIE("Database unavailable");

$query = "select * from table";
$rs = mysql_query($query, $conn);
$rw = mysql_fetch_array($rs);
foreach($rw as $value){
echo $rw['col_name'];
}

答案 1 :(得分:0)

尝试使用此代码

$servername="(server name)"; // use local if local server
$conn=new PDO("sqlsrv:server=$servername; database=dbname");
if($conn){

    //echo "success";
}
else{
    echo "error";
    die(print_r(sqlsrv_errors(),true));
}