使用PHP从Linux服务器连接到远程MS SQL数据库
我已经在Linux服务器上托管了我的网站,我想连接MS SQL数据库。我在编程中使用过PHP。我已经联系了这两个服务器提供商,他们在他们的范围内提供了帮助。但是我的问题没有解决,你能指导我怎么做吗。我的代码如下 当我运行此程序时,它显示“找不到驱动程序1” 请引导我。提前谢谢使用PHP从Linux服务器连接到远程MS SQL数据库,php,sql-server,linux,database,database-connection,Php,Sql Server,Linux,Database,Database Connection,我已经在Linux服务器上托管了我的网站,我想连接MS SQL数据库。我在编程中使用过PHP。我已经联系了这两个服务器提供商,他们在他们的范围内提供了帮助。但是我的问题没有解决,你能指导我怎么做吗。我的代码如下 当我运行此程序时,它显示“找不到驱动程序1” 请引导我。提前谢谢 <?php //echo phpinfo(); ?> <!DOCTYPE html> <html> <head> <title></title
<?php
//echo phpinfo();
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>testing</h1>
</body>
</html>
<?php
// Server in the this format: <computer>\<instance name> or
// <server>,<port> when using a non default port number
$server = 'server:port';
$myDB = "DatabaseName";
// Connect to MSSQL
$link = mssql_connect($server, 'username', 'password');
if (!$link) {
die('Something went wrong while connecting to MSSQL');
}
else
{
echo "success";
}
?>
测试
谢谢@Rony的帮助
<?php
try {
$conn = new PDO("sqlsrv:Server='server_name';Database=database_name", 'username', 'password');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (Exception $e) {
die(print_r($e->getMessage() ));
}
$tsql = "select * from table_name";
$getResults = $conn->prepare($tsql);
$getResults->execute();
$results = $getResults->fetchAll(PDO::FETCH_BOTH);
foreach ($results as $row) {
echo $row['0'].' '.$row['6'];
echo "<br>";
}
?>