SQL Relay是一個開源的數據庫池連接代理服務器
二、SQL Relay支持哪些數據庫?
* Oracle * mysql * mSQL * PostgreSQL * Sybase * MS SQL Server * IBM DB2 * Interbase * Sybase * SQLite * Lago * ODBC * MS Access
三、安裝和配置;
不說廢話了,開始安裝SQL Relay,到 http://sqlrelay.sourceforge.net/ 去下載相應的軟件安裝SQL Relay需要先安裝Rudiments, 在 http://sqlrelay.sourceforge.net/download.Html 可以找到
1、安裝Rudiments:
# tar vxzf rudiments-0.28.2.tar.gz# cd rudiments-0.28.2# ./configure --prefix=/usr/local/rudiments# make# make install至此,rudiments安裝結束
2、安裝SQL Relay:
# tar vxzf sqlrelay-0.36.4.tar.gz# cd sqlrelay-0.36.4# ./configure --prefix=/usr/local/sqlrelay --with-rudiments-prefix=/usr/local/rudiments --with-mysql-prefix=MySQL安裝路徑 --with-freetds-prefix=FreeTDS安裝路徑 --with-oracle-home=Oracle安裝路徑 --with-PHP-prefix=PHP安裝路徑# make# make install安裝結束,以上編譯參數根據個人需要來設定,因為我同時需要Oracle SQLserver MySQL,所以才加了這麼多參數的3、設置PHP:
修改php.ini extension_dir = "./"把以上內容修改為: extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922"根據PHP安裝的路徑來修改,並不是每個版本的PHP都是這個路徑在php.ini中添加如下內容 extension=sql_relay.so
接下來,介紹SQL Relay如何連接SQL Server修改FreeTDS的配置文件freetds.conf加入如下內容:
[msde]host = 172.16.20.203port =1433tds version = 8.0client charset = GB2312請根據個人需求來修改
4、修改SQL Relay的配置文件
# cd /usr/local/sqlrelay/etc# cp sqlrelay.conf.example sqlrelay.conf把sqlrelay.conf的內容改為: <?XML version="1.0"?><!DOCTYPE instances SYSTEM "sqlrelay.dtd"><instances><instance id="msdetest" port="9000" socket="/tmp/msdetest.socket" dbase="freetds" connections="5" maxconnections="10" maxqueuelength="0" growby="1" ttl="60" endofsession="commit" sessiontimeout="5" runasuser="nobody" runasgroup="nobody" cursors="5" authtier="listener" handoff="pass"><users><user user="sa" passWord="sa"/></users><connections><connection connectionid="msdetest" string="server=msde;db=pubs;user=sa;password=sa;" metric="1"/></connections></instance></instances>
四、啟動SQL Relay,並測試;
1、啟動 SQL Relay
# eXPort PATH=$PATH:/usr/local/sqlrelay/bin# sqlr-start -id msdetest
2、使用SQL工具:
# sqlrsh -id msdetest可以直接輸入SQL語句
停止SQL Relay: # sqlr-stop msdetest
3、測試PHP:
寫一個PHP文件,內容如下:
<?$con=sqlrcon_alloc("msdetest",9000,"/tmp/msdetest.socket","sa","sa",0,1);$cur=sqlrcur_alloc($con);sqlrcur_sendQuery($cur,"select * from t_gifts"); for ($row=0; $row<sqlrcur_rowCount($cur); $row++) { for ($col=0; $col<sqlrcur_colCount($cur); $col++) { echo sqlrcur_getField($cur,$row,$col); echo ","; } echo "<br>\n"; }sqlrcur_free($cur);sqlrcon_free($con);?>執行這個PHP文件,看看能不能出現數據全文結束~~Good LUCk!!!