[关闭]
@nalan90 2022-06-28T16:17:15.000000Z 字数 1685 阅读 342

CentOS 7安装php7.3及SQL Server扩展

Linux


1、安装php73
  1. yum install epel-release yum-utils
  2. yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
  3. yum install -y php73 php73-php-devel php73-php-fpm php73-php-cli php73-php-bcmath php73-php-gd php73-php-json php73-php-mbstring php73-php-mcrypt php73-php-mysqlnd php73-php-opcache php73-php-pdo php73-php-pecl-crypto php73-php-pecl-mcrypt php73-php-pecl-geoip php73-php-pecl-swoole php73-php-recode php73-php-snmp php73-php-soap php73-php-xml php73-php-redis
2、安装pecl
  1. wget http://pear.php.net/go-pear.phar -O go-pear.php
  2. /opt/remi/php73/root/usr/bin/php go-pear.php
3、安装依赖
  1. curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssqlrelease.repo
  2. yum -y install msodbcsql mssql-tools unixODBC-devel
4、安装PHP SQL Server扩展
  1. sudo pecl install sqlsrv
  2. sudo pecl install pdo_sqlsrv
  3. 编辑/etc/opt/remi/php73/php.d/20-pdo.ini
  4. extension=pdo
  5. extension=sqlsrv.so
  6. extension=pdo_sqlsrv.so
5、测试连接
  1. https://www.microsoft.com/en-us/sql-server/developer-get-started/php/rhel
  2. <?php
  3. $serverName = "121.33.75.18,3019";
  4. $connectionOptions = [
  5. "Database" => "middleDB",
  6. "Uid" => "kes",
  7. "PWD" => "Kblkes2020"
  8. ];
  9. //Establishes the connection
  10. $conn = sqlsrv_connect($serverName, $connectionOptions);
  11. $tsql= "SELECT orderNum, shipmentNum FROM kes_order_master;";
  12. $getResults= sqlsrv_query($conn, $tsql);
  13. echo ("Reading data from table" . PHP_EOL);
  14. if ($getResults == FALSE)
  15. die(FormatErrors(sqlsrv_errors()));
  16. while ($row = sqlsrv_fetch_array($getResults, SQLSRV_FETCH_ASSOC)) {
  17. echo ($row['orderNum'] . " " . $row['shipmentNum'] . PHP_EOL);
  18. }
  19. sqlsrv_free_stmt($getResults);
  20. function FormatErrors( $errors )
  21. {
  22. /* Display errors. */
  23. echo "Error information: ";
  24. foreach ( $errors as $error )
  25. {
  26. echo "SQLSTATE: ".$error['SQLSTATE']."";
  27. echo "Code: ".$error['code']."";
  28. echo "Message: ".$error['message']."";
  29. }
  30. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注