OS:Ubuntu 18.04 Server
Apache2.4
PHP7.2
因PHP7.0以後無sybase相關function,需透過freetds為連線介接,再使用PDO相關function進行連線。
1. 安裝相關套件
2.設定freetds
sudo apt install php7.2-sybase
2.設定freetds
sudo vim /etc/freetds/freetds.conf
[global]
client charset = UTF-8
charset = utf8
[sybase_db]
host = db.com.tw
port = 5000
tds version = 5.0
3. 使用PDO function測試是否連線成功。
<?php
$db_host = "sybase_db";
$db_user = "帳號";
$db_pass = "密碼";
$db_select = "dbname";
$dbconnect = "dblib:host=".$db_host.";dbname=".$db_select;
$pdo_sybase = new PDO($dbconnect, $db_user, $db_pass);
$sql = "select * from sybase_table where 1=1";
$res = pdo_sybase->query($sql);
while ($row = $res->fetch()){
print_r($row);
}
?>