[转]SQL Relay使用
一、SQL Relay是什么?
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.203
port =1433
tds version = 8.0
client 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!!!
作者:leoking01 发表于2014-11-12 10:31:48 原文链接
阅读:6 评论:0 查看评论
_________________________________________________________________________________________________________________________________________________
每一个不曾起舞的日子,都是对生命的辜负。
But it is the same with man as with the tree. The more he seeks to rise into the height and light, the more vigorously do his roots struggle earthward, downward, into the dark, the deep - into evil.
其实人跟树是一样的,越是向往高处的阳光,它的根就越要伸向黑暗的地底。----尼采
每一个不曾起舞的日子,都是对生命的辜负。
But it is the same with man as with the tree. The more he seeks to rise into the height and light, the more vigorously do his roots struggle earthward, downward, into the dark, the deep - into evil.
其实人跟树是一样的,越是向往高处的阳光,它的根就越要伸向黑暗的地底。----尼采