티스토리 뷰

1. Install FreeTDS and the PHP MS SQL extension
sudo apt-get install freetds-common freetds-bin unixodbc php5-sybase



2. Restart Apache

sudo /etc/init.d/apache2 restart


3. Test FreeTDS

tsql -H your.server.name -p 1433 -U yourusername -P yourpassword -D yourdatabasename


4. Configure FreeTDS

sudo vim /etc/freetds/freetds.conf

Add this at the end of the file:

[yourserver]
host = your.server.name
port = 1433
tds version = 8.0

5. Test FreeTDS using server name

tsql -S yourserver -U yourusername -P yourpassword -D yourdatabasename

6. Test in PHP

$link = mssql_connect('yourserver', 'yourusername', 'yourpassword');
 
if (!$link)
    die('Unable to connect!');
 
if (!mssql_select_db('yourdatabasename', $link))
    die('Unable to select database!');
 
$result = mssql_query('SELECT * FROM yourtable');
 
while ($row = mssql_fetch_array($result)) {
    var_dump($row);
}
 
mssql_free_result($result);


'코딩 > Linux' 카테고리의 다른 글

리눅스(debian/ubuntu) 서버에서 PHP와 MSSQL 연동하기  (0) 2015.04.24
댓글
댓글쓰기 폼