centos 安装 mssql 支持php访问mssql(仅64位)

1、安装所需库

yum install php.x86_64
yum install php-odbc.x86_64
yum install php-pear.noarch
yum install php-pecl-apc.x86_64
yum install php-xml.x86_64
yum install php-xmlrpc.x86_64
yum install php-tidy.x86_64
yum install php-intl.x86_64
yum install php-imap.x86_64
yum install php-pecl-memcache.x86_64

2、下载 mssql 的OSBC驱动
http://www.microsoft.com/en-us/download/confirmation.aspx?id=28160

3、安装
cd ~
tar xvf sqlncli-11.0.1790.0.tar.gz

cd ./sqlncli-11.0.1790.0

./build_dm.sh
如果有提示输入”YES” 必须大写。

如果成功

./install.sh install
如果有提示输入”YES” 必须大写。

校验是否安装
odbcinst -q -d -n “SQL Server Native Client 11.0”

4、其他

vi /etc/odbcinst.ini 查看内容

[PostgreSQL]
Description=ODBC for PostgreSQL
Driver=/usr/lib/psqlodbc.so
Setup=/usr/lib/libodbcpsqlS.so
Driver64=/usr/lib64/psqlodbc.so
Setup64=/usr/lib64/libodbcpsqlS.so
FileUsage=1

[MySQL]
Description=ODBC for MySQL
Driver=/usr/lib/libmyodbc5.so
Setup=/usr/lib/libodbcmyS.so
Driver64=/usr/lib64/libmyodbc5.so
Setup64=/usr/lib64/libodbcmyS.so
FileUsage=1

[SQL Server Native Client 11.0]
Description=Microsoft SQL Server ODBC Driver V1.0 for Linux
Driver=/opt/microsoft/sqlncli/lib64/libsqlncli-11.0.so.1790.0
Threading=1
UsageCount=1

vi /etc/odbc.ini 开始空文件

编辑内容如下:

[连接名]
Driver = SQL Server Native Client 11.0
Server = tcp:host网址,1433
Trace=Yes

保存即可。

5、配置 httpd.conf文件,不知道有没有用
Add these two lines to /etc/httpd/conf/httpd.conf
SetEnv ODBCSYSINI /etc
SetEnv ODBCINI /etc/odbc.ini

测试
# isql -v 连接名 ‘用户名’ ‘密码’

将显示如下表示连接成功:
+—————————————+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+—————————————+
SQL> quit

http://strangenut.com/blogs/dacrowlah/archive/2012/04/13/installing-and-using-the-microsoft-sql-server-odbc-driver-for-linux.aspx

6、编辑php程序:
prepare(“$query”);
$stmt->execute();
while ($row = $stmt->fetch()) {
print_r($row);
}
$dbh = null;
unset($dbh); unset($stmt);

?>

http://php.net/manual/zh/ref.pdo-odbc.php

http://phplens.com/phpeverywhere/node/view/9

7、注意:
http://www.vixual.net/blog/archives/133

PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib64/php/modules/module.so’ – /usr/lib64/php/modules/module.so: cannot open shared object file: No such file or directory in Unknown on line 0
; Enable mcrypt extension module

編輯 /etc/php.d/mcrypt.ini,將第 2 行的
将 extension=module.so 改成 extension=mcrypt.so
# service httpd restart

Published by

admin

互联网web开发管理