今單嘢搞咗我幾日,真慘!我用 Bitnami 個 DreamFactory image 就咩事都冇,自己一步一步安裝就掂都有問題,差啲俾佢激死,想過要放棄添!
喺 Ubuntu 14.04 LTS 上安裝 DreamFactory 基本上沒有什麼麻煩,照著 online 說明做已經可以。
準備 Ubuntu 時可以選 LAMP 再加 SSH Server,因為,反正 DreamFactory 都要用到 Apache2 和 mysql,由得個 installer 裝好過自己慢慢打字嚟安裝啦,不過,安裝 packages 的時候最好都仲係分類一步一步嚟,唔好照跟 online 中的例子一次過打哂啲 packages 一次過安裝。
Create database 嘅時候我係用:
CREATE DATABASE dreamfactory CHARACTER SET utf8 COLLATE utf8_general_ci;
直接叫 mysql 用 UTF-8,因為我啲 projects 一直都係用 unicode (NVARCHAR)。
咩係 DreamFactory?哩隻 Open Source 軟件好勁,可以幫你個 SQL Database 自動搞啲 RESTFUL API 出嚟,唔使 10 分鐘即刻有 json 接口搞 mobile apps,Tables + Views + Stored Procedures 都可以直接調用,非常方便!
安裝完 DreamFactory 仲要安裝同 MS SQL 接駁嘅 Connectors,online 都有說明,其實就係一句
$ sudo apt-get install php5-sybase
就係咁簡單,不過如果你要用到 UTF-8 (中文字) 咁就一切都唔同咗,當你用 DreamFactory 攞 MS SQL 啲料嘅時候,Schema 同 Tables list 都會好正常咁出現,不過一旦 retrieve 的 data 就會遇上 SQLSTATE[HY000]: Error code 4004。
哩個 Error 同 FreeTds 有關,php5-sybase 要用佢嚟 connect MS SQL,你要 edit freetds.conf 內嘅設定先用得 UTF-8. 通常可以喺 /etc/freetds 搵到 freetds.conf。一開始佢大概係咁嘅樣:
[global] # TDS protocol version ; tds version = 4.2 # Whether to write a TDSDUMP file for diagnostic purposes # (setting this to /tmp is insecure on a multi-user system) ; dump file = /tmp/freetds.log ; debug flags = 0xffff # Command and connection timeouts ; timeout = 10 ; connect timeout = 10 # 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 # A typical Sybase server [egServer50] host = symachine.domain.com port = 5000 tds version = 5.0 # A typical Microsoft server [egServer70] host = ntmachine.domain.com port = 1433 tds version = 7.0
改為:
[global] # TDS protocol version tds version = 8.0 # Whether to write a TDSDUMP file for diagnostic purposes # (setting this to /tmp is insecure on a multi-user system) dump file = /tmp/freetds.log debug flags = 0xffff # Command and connection timeouts timeout = 30 connect timeout = 30 # 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 = 20971520
freetds.conf 嘅 attributes 詳細解釋在這裡可以找到,最重要係要將
tds version = 8.0
掂解要 8.0? 又關 Microsoft 事囉,TDS Protocol Versions 在此有詳細解釋,我試過 7.2/ 7.3/ 8/10.0 都唔得,一定要 8.0,我嘅 MS SQL 係 2008,我都唔明!?遲早會用到 MS SQL 2012,到時掂算?有空我再裝個 trail 嚟試,不過目前要搞 mobile apps,冇時間測試!
啊,UTF-8 仲有少少嘢要 set,包括 php5 同 Apache2,比較簡單,自己去 google 下就有答案。
今篇到此完結,thanks!