步骤 1. 安装 PHP

步骤 1. 安装 PHP

我正在尝试在我的 Ubuntu 16.04 操作系统中安装 sqlsrv 驱动程序,但出现此错误

running: make
/bin/bash /tmp/pear/temp/pear-build-rootliPAYQ/sqlsrv-4.3.0/libtool 
--mode=compile g++ -std=c++11 -I. -I/tmp/pear/temp/sqlsrv -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootliPAYQ/sqlsrv-4.3.0/include 
-I/tmp/pear/temp/pear-build-rootliPAYQ/sqlsrv-4.3.0/main  
-I/tmp/pear/temp/sqlsrv -I/usr/include/php/20151012 -I/usr/include
/php/20151012/main -I/usr/include/php/20151012/TSRM -I/usr/include
/php/20151012/Zend -I/usr/include/php/20151012/ext -I/usr/include
/php/20151012/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 
-I/tmp/pear/temp/sqlsrv/shared/  -DHAVE_CONFIG_H  -std=c++11 
-D_FORTIFY_SOURCE=2 -O2 -fstack-protector   -c /tmp/pear/temp/sqlsrv
/conn.cpp -o conn.lo

 libtool: compile:  g++ -std=c++11 -I. -I/tmp/pear/temp/sqlsrv -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootliPAYQ/sqlsrv-4.3.0/include -I/tmp/pear/temp/pear-build-rootliPAYQ/sqlsrv-4.3.0/main 

-I/tmp/pear/temp/sqlsrv -I/usr/include/php/20151012 -I/usr/include/php/20151012/
main -I/usr/include/php/20151012/TSRM -I/usr/include/php/20151012/Zend 
-I/usr/include/php/20151012/ext -I/usr/include/php/20151012/ext/date/
lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 
-I/tmp/pear/temp/sqlsrv/shared/ 
-DHAVE_CONFIG_H -std=c++11 -D_FORTIFY_SOURCE=2 -O2 -fstack-protector -c /tmp/pear/
temp/sqlsrv/conn.cpp  -fPIC -DPIC -o .libs/conn.o In file included from /tmp/pear/
temp/sqlsrv/shared/xplat.h:99:0,
from /tmp/pear/temp/sqlsrv/shared/typedefs_for_linux.h:23,
from /tmp/pear/temp/sqlsrv/shared/xplat_winnls.h:24,
from /tmp/pear/temp/sqlsrv/shared/FormattedPrint.h:24,
from /tmp/pear/temp/sqlsrv/shared/core_sqlsrv.h:41,
from /tmp/pear/temp/sqlsrv/php_sqlsrv.h:25,
from /tmp/pear/temp/sqlsrv/conn.cpp:20:
/tmp/pear/temp/sqlsrv/shared/xplat_intsafe.h:50:29: error: conflicting declaration 
‘typedef windowsULong_t DWORD’
 typedef windowsULong_t      DWORD;
                         ^
In file included from /usr/include/sql.h:19:0,
             from /tmp/pear/temp/sqlsrv/shared/xplat.h:30,
             from /tmp/pear/temp/sqlsrv/shared/typedefs_for_linux.h:23,
             from /tmp/pear/temp/sqlsrv/shared/xplat_winnls.h:24,
             from /tmp/pear/temp/sqlsrv/shared/FormattedPrint.h:24,
             from /tmp/pear/temp/sqlsrv/shared/core_sqlsrv.h:41,
             from /tmp/pear/temp/sqlsrv/php_sqlsrv.h:25,
             from /tmp/pear/temp/sqlsrv/conn.cpp:20:
/usr/include/sqltypes.h:96:24: note: previous declaration as ‘typedef long     unsigned int DWORD’
typedef unsigned long  DWORD;
                    ^
Makefile:194: recipe for target 'conn.lo' failed
make: *** [conn.lo] Error 1
ERROR: `make' failed

我该如何解决这个问题?请注意,我的 PHP 版本是 7.0.22,操作系统是 ubuntu0.16.04.1 (cli) (NTS)。

答案1

您应该遵循 Microsoft 的官方安装说明。

看:在 Linux 和 macOS 上安装 Microsoft ODBC Driver for SQL Server(还PDF 手册)。

以下步骤是从指南中复制的:

步骤 1. 安装 PHP

sudo su 
apt-get update 
apt-get -y install php7.0 mcrypt php7.0-mcrypt php-mbstring php-pear php7.0-dev 
php7.0-xml 

步骤 2. 安装先决条件

sudo su 
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list 
exit 
sudo apt-get update 
sudo ACCEPT_EULA=Y apt-get install msodbcsql mssql-tools 
sudo apt-get install unixodbc-dev 
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile 
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc 
source ~/.bashrc 

步骤 3. 安装适用于 Microsoft SQL Server 的 PHP 驱动程序

sudo pear config-set php_ini `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` system 
sudo pecl install sqlsrv 
sudo pecl install pdo_sqlsrv

答案2

如果添加以下内容,上述答案将有效:

将下面的 7.x 更改为你当前的版本 ls /etc/php/ 来找到它

回显“扩展名=sqlsrv.so”>> /etc/php/7.x/apache2/php.ini 回显“扩展名=pdo_sqlsrv.so”>> /etc/php/7.x/apache2/php.ini

相关内容