2012-06-04 2 views
2

나는 리눅스 서버에서 PHP adodb를 사용하여 MSSQL 서버에 연결하려고합니다.php adodb MSSQL connection

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"); 

나는 냠 등을 통해 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); 

내 ADODB 실 거예요 연결 왜 어떤 아이디어, 또는 예 내가 어떻게 연결할 수 있는지에 대해 많은 관심을 보일 것입니다.

답변

5

나는이 포럼에서보고이 문제를 해결했습니다 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); 
?> 

희망.

1

위의 PHP 5.3을 사용하면 php_mssql 모듈을 더 이상 지원하지 않습니다.

해결책은 http://www.microsoft.com/en-us/download/details.aspx?id=20098에서 MicroSoft PHP 드라이버를 다운로드하는 것입니다.

이 설치 프로그램은 modul dll 파일을 PHP 확장 디렉토리에 추출합니다. 당신은 (PHP 5.3 스레드를 위해 다음과 같은 예를 들어) INI를 PHP에서

올바른 버전을 포함합니다 :이 후

extension=php_sqlsrv_53_ts.dll 

가 다시 adboDb를 사용할 수 있지만 adodbtype로 mssqlnative을 사용해야합니다. 그리고 ip 및 port와의 연결이 작동하지 않지만 ipaddress\\SERVERNAME이 작동했습니다 (예제 코드 참조)

<?php include("adodb5/adodb.inc.php"); 
//create an instance of the ADO connection object 
$conn =&ADONewConnection ('mssqlnative'); 
//define connection string, specify database driver 

// $conn->Connect('xxx.xxx.x.xxx:1400', 'user', 'password', 'DbName'); 
$conn->Connect('xxx.xxx.x.xxx\\SERVERNAME', '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); ?>