PHP 5.6 ODBC扩展安装与配置
ODBC扩展安装
编译安装问题分析
编译安装好了PHP5.6之后,发现缺少odbc扩展,于是到PHP源码目录下的ext/odbc目录下编译
|
|
这个时候报错:
|
|
网上搜到的解决方案一般是安装 unixODBC-devel 、 libiodbc-devel 还有 libtool-ltdl-devel。可是都安装好了之后还是这个样子。
由于是在一台无法访问外网的机器上安装的,折腾了半天,也没弄好,猜测可能有些依赖没装好。试了试本地有外网的机器上用docker下载PHP5.6,安装odbc扩展试试,结果还是一样的问题。
后来发现github上这个issues
tianon commented on May 29, 2015 via email That one’s failing at build, not at configure. 😕 tianon commented on May 29, 2015 So, the generated ./configure script has a number of those test “$PHP_XXX” = “no” && PHP_XXX=yes lines. If I comment them all out and run it again, it works and the whole module builds successfully. WUT
大概意思是./configure脚本中,有一些测试的内容,把他们注释掉就可以了
|
|
到这里odbc扩展就安装成功了。
ODBC安装SQL Server驱动
PHP使用odbc扩展连接SQL Server还需要为ODBC安装SQL Server驱动,参考SQL Server文档
什么是ODBC驱动呢?
|
|
这里的 Driver={SQL Server}; 就是ODBC驱动,如果未安装驱动则会报错。 [unixODBC][Driver Manager]Can’t open lib ‘ SQL Server’ : file not found
SQL Server的驱动可以在这里找到,注意根据系统进行选择。
由于是 CentOS 7 的服务器,找到 CentOS 7 下只有17版本的驱动,安装之后,驱动部分改为
|
|
结果还是不能使用。
想来应该是版本太新了,不支持?想了想CentOS 7 和 RHEL 7是同一家族的,试了试RHEL 7下的msodbcsql-13.0.1.0-1.x86_64.rpm
|
|
这回终于完美解决了。