Installation Centos7.5 php7.2 sql server connected pdo_sqlsrv
First, the addition of Microsoft's source
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssqlrelease.repo
Second, to prevent conflicts uninstall the previous version (optional)
yum remove unixODBC
Third, the installation drive (to be fitted with three indispensable)
yum install msodbcsql mssql-tools unixODBC-devel
Fourth, the expansion pack download pdo_sqlsrv
wget http://pecl.php.net/get/pdo_sqlsrv-5.3.0.tgz
Fifth, unzip
tar -zxvf pdo_sqlsrv-5.3.0.tgz
Sixth, the files are decompressed directory
cd pdo_sqlsrv-5.3.0
Seven, execute the command
-
/usr/ local/php/bin/phpize
-
-
./configure -- with-php-config=/usr/local/php/bin/php-config
Eight, compile and install
make && make install
解决编译错误问题:
sudo yum install centos-release-scl
sudo yum install devtoolset-7
scl enable devtoolset-7 bash
Nine, update php.ini
Modify /usr/local/php/etc/php.ini Find: extension = extension = Add again last behind the extension = "pdo_sqlsrv.so"
Ten, restart lnmp
lnmp restart
POD connection Example:
-
define( 'MSSQL_HOST','111.15.25.222,6666');
-
define( 'MSSQL_USER','sa');
-
define( 'MSSQL_PASSWORD','password');
-
define( 'MSSQL_DBNAME','demo');
Note: is a comma between the port number with the address.
-
$ this->dbms = 'sqlsrv';
-
$ this->host = MSSQL_HOST;
-
$ this->user = MSSQL_USER;
-
$ this->password = MSSQL_PASSWORD;
-
$ this->dbname = MSSQL_DBNAME;
-
$ this->dsn = "$this->dbms:Server=$this->host;Database=$this->dbname";
-
$ this->DB = new PDO($this->dsn, $this->user, $this->password);
Note: dsn part, with mysql and dblib is not the same.
It's done.