Centos7.5 php7.2 mounting pdo_sqlsrv connection sql server (rpm)

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

  1.  
    /usr/ local/php/bin/phpize
  2.  
     
  3.  
    ./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:

  1.  
    define( 'MSSQL_HOST','111.15.25.222,6666');
  2.  
    define( 'MSSQL_USER','sa');
  3.  
    define( 'MSSQL_PASSWORD','password');
  4.  
    define( 'MSSQL_DBNAME','demo'); 

Note: is a comma between the port number with the address.

  1.  
    $ this->dbms = 'sqlsrv';
  2.  
    $ this->host = MSSQL_HOST;
  3.  
    $ this->user = MSSQL_USER;
  4.  
    $ this->password = MSSQL_PASSWORD;
  5.  
    $ this->dbname = MSSQL_DBNAME;
  6.  
    $ this->dsn = "$this->dbms:Server=$this->host;Database=$this->dbname";
  7.  
    $ this->DB = new PDO($this->dsn, $this->user, $this->password);

Note: dsn part, with mysql and dblib is not the same.

 

It's done.

Guess you like

Origin www.cnblogs.com/GarfieldTom/p/11440792.html