pdo_sqlsrv

 

介紹

 

Homepage

https://github.com/Microsoft/msphpsql

Prebuilt binaries

# from the Github project page

# Ubuntu16~18, Centos7 ...

https://github.com/Microsoft/msphpsql/releases

 


Compile From Source Code

 

# to avoid conflicts

yum remove unixODBC-utf16 unixODBC-utf16-devel

# Prerequisites

yum install php70-php-devel

# Install the ODBC driver for Centos

curl https://packages.microsoft.com/config/rhel/6/prod.repo > \

/etc/yum.repos.d/mssql-release.repo

# msodbcsql 有關 Package

ACCEPT_EULA=Y yum install msodbcsql17

# unixODBC development headers

yum install unixODBC-devel

# optional: for bcp and sqlcmd

ACCEPT_EULA=Y yum install mssql-tools

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc

source ~/.bashrc

Get Source & Compile

# sqlsrv

wget https://pecl.php.net/get/sqlsrv-5.3.0.tgz                 # pdo_sqlsrv 依賴 sqlsrv

tar xvzf sqlsrv-5.3.0.tgz

cd sqlsrv-5.3.0/

phpize

./configure --with-php-config=/usr/bin/php-config

make

make install

# pdo_sqlsrv

wget https://pecl.php.net/get/pdo_sqlsrv-5.3.0.tgz

tar xvzf pdo_sqlsrv-5.3.0.tgz

cd sqlsrv-5.3.0/

phpize

./configure --with-php-config=/usr/bin/php-config

make

make install

# Checking

ls /usr/lib64/php/modules/*sqlsrv*

 


Troubleshoot

 

[1]

Error

cc1plus: error: unrecognized command line option "-std=c++11"
cc1plus: error: unrecognized command line option "-std=c++11"
make: *** [conn.lo] Error 1

原因: requires a more recent GCC than the default

rpm -qa | grep gcc

libgcc-4.4.7-23.el6.x86_64
gcc-4.4.7-23.el6.x86_64
gcc-c++-4.4.7-23.el6.x86_64

解決

https://datahunter.org/scl#devtoolset-7

[2]

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo_sqlsrv.so'
 - /usr/lib64/php/modules/pdo_sqlsrv.so: undefined symbol: php_pdo_register_driver in Unknown on line 0

[1] 沒有安 pdo

yum install php-pdo

[2] pdo.so was loading after pdo_sqlsrv.so

/etc/opt/remi/php70/php.d/30-pdo_sqlsrv.ini

; mssql
extension=sqlsrv.so
extension=pdo_sqlsrv.so

 


 

 

 

Creative Commons license icon Creative Commons license icon