$ sudo wget http://people.centos.org/tru/devtools-1.1/devtools-1.1.repo -P /etc/yum.repos.d
$ sudo sh -c 'echo "enabled=1" >> /etc/yum.repos.d/devtools-1.1.repo'
$ sudo yum install devtoolset-1.1
devtools will be installed under /opt/centos/devtoolset-1.1.
To use gcc from devtoolset, use the following command. This command will launch a new shell, wherein all environment variables are automatically set to use devtools.
$ scl enable devtoolset-1.1 bash
$ gcc --version
gcc (GCC) 4.7.2 20121015 (Red Hat 4.7.2-5)
Alternatively, you can explicitly define the following variables to use devtools.
export CC=/opt/centos/devtoolset-1.1/root/usr/bin/gcc
export CPP=/opt/centos/devtoolset-1.1/root/usr/bin/cpp
export CXX=/opt/centos/devtoolset-1.1/root/usr/bin/c++
1、发现如下错误:
fatal error: sql.h: No such file or directory
提示缺少头文件,直接安装unixodbc的工具包即可:
yum install unixODBC-devel
参考链接:http://ask.xmodulo.com/upgrade-gcc-centos.html
2、发现如下错误:
make: *** [conn.lo] Error 1
ERROR: `make' failed
解决办法:
sudo yum install centos-release-scl
sudo yum install devtoolset-7
scl enable devtoolset-7 bash
参考链接:https://github.com/Microsoft/msphpsql/issues/726
3、遇到类似如下错误:
This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x64: http://go.microsoft.com/fwlink/?LinkId=163712
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssqlrelease.repo
#curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssqlrelease.repo 和上面的语句、视版本而定
yum remove unixODBC
yum install msodbcsql mssql-tools unixODBC-devel
pecl install sqlsrv
pecl install pdo_sqlsrv
4、php7 pdo centos mssql
(注:如果遇到 tsql、osql、sqlcmd有一种可以连接,但是thinkphp连接不上的情况;或者有如下提示的:[IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified,请重启php-fpm)
thinkphp5.0 config 配置如下:
'productDb'=>[
'type'=>'sqlsrv',
'username'=>'xxx',
'password'=>'xxxx',
'database'=>'HQDB',
'hostname'=>'xx.xxx.xx.xx',
'hostport'=>'9898',
'dns'=>'',
];
连接数据库代码如下:
$productDbArr = Config::get('productDb');
// Open connection
$db_connect = \think\Db::connect($productDbArr);