우분투 컴퓨터에서 Windows SQL Server로 PHP를 MSSQL에 연결하는 데 사용하는 코드는 다음과 같습니다.이 코드가 도움이되는지는 모르겠지만이 코드는 정상적으로 작동하므로 지금 작동합니다. 우리 환경 ...
보시다시피 mssql_ * 함수 대신 PDO를 사용합니다. 우분투에서 dblib 드라이버를 얻으려면 php5-sybase 패키지를 설치해야했습니다.
PHP :
<?php
try{
$con = new PDO("dblib:dbname=$dbname;host=$servername", $username, $password);
}catch(PDOException $e){
echo 'Failed to connect to database: ' . $e->getMessage() . "\n";
exit;
}
?>
/etc/odbc.ini
# Define a connection to the MSSQL server.
# The Description can be whatever we want it to be.
# The Driver value must match what we have defined in /etc/odbcinst.ini
# The Database name must be the name of the database this connection will connect to.
# The ServerName is the name we defined in /etc/freetds/freetds.conf
# The TDS_Version should match what we defined in /etc/freetds/freetds.conf
[mssqldb]
Description = MSSQL Server
Driver = freetds
Database = MyDB
ServerName = mssqldb
TDS_Version = 8.0
/etc/odbcinst.ini
# Define where to find the driver for the Free TDS connections.
[freetds]
Description = MS SQL database access with Free TDS
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/i386-linux-gnu/odbc/libtdsS.so
UsageCount = 1
/etc/freetds/freetds.conf
[global]
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
# Define a connection to the MSSQL server.
[mssqldb]
host = mssqldb
port = 1433
tds version = 8.0
이됩니까? 해당 서버에서 주어진 포트를 확인하십시오. 해당 포트에 텔넷하여 연결을 수락하는지 확인하십시오. – PoX
또한 원격 연결을 허용하는 mssql 서버 설정입니까? http://blogs.msdn.com/b/walzenbach/archive/2010/04/14/how-to-enable-remote-connections-in-sql-server-2008.aspx –
'sql'또는 ' apache '태그가 질문에 적합합니다. –