Sha*_*ane 2 php sql-server adodb-php
我有一个linux服务器,我正在尝试使用php adodb连接到MSSQL服务器.
include('adodb5/adodb.inc.php');
$conn =& ADONewConnection('odbc_mssql');
$dsn = "Driver={SQL Server};Server=MSSERVER;Database=Northwind;";
$conn->Connect($dsn,'sa','password')or die("Unable to connect to server");
Run Code Online (Sandbox Code Playgroud)
我通过yum等安装mssql,我知道服务器可以连接到它,因为我尝试了以下内容:
$db = @mssql_connect("MSSERVER","sa","password") or die("Unable to connect to server");
mssql_select_db("Northwind");
// Do a simple query, select the version of
// MSSQL and print it.
$version = mssql_query('SELECT @@VERSION');
$row = mssql_fetch_array($version);
echo $row[0];
// Clean up
mssql_free_result($version);
Run Code Online (Sandbox Code Playgroud)
任何想法为什么我的adodb不会连接,或任何关于如何连接的例子将非常感激.
我通过查看此论坛解决了这个问题:http://ourdatasolution.com/support/discussions.html?topic = 4200.0
正确的代码是:
<?php
include("adodb5/adodb.inc.php");
//create an instance of the ADO connection object
$conn =&ADONewConnection ('mssql');
//define connection string, specify database driver
$conn->Connect('xxx.xxx.x.xxx:1400', 'user', 'password', 'DbName');
//declare the SQL statement that will query the database
$query = "select * from table";
$rs = $conn->execute($query);
//execute the SQL statement and return records
$arr = $rs->GetArray();
print_r($arr);
?>
Run Code Online (Sandbox Code Playgroud)
希望能帮助别人.
| 归档时间: |
|
| 查看次数: |
21141 次 |
| 最近记录: |