nginx php-fpm不使用freetds但使用php

时间:2016-03-30 14:19:40

标签: php nginx freetds

我有一个使用mssqlfreetds相关联的代码。当我从命令行运行时它完美地工作。当我通过浏览器使用nginx php-fmp运行时失败。代码如下:

 <?php
  $host = "myhost";
  $user = "username";
  $pass = "password";
  $db = "database";
  $table = "user";
  try {
    $conn = mssql_connect($host, $user, $pass);
    mssql_select_db( $db, $conn );
    $query = "SELECT COUNT(*) FROM [".$db."].[dbo].[".$table."]";
    $query_result = mssql_query( $query , $conn );
    echo "The count of ".$table." is: ";
    $result =  mssql_result ($query_result,0,0);
    var_export($result);
    mssql_close($conn); // close connection

  } catch (Exception $e) {
    throw new Exception("The script exited with an exception    ===========================".PHP_EOL." ERROR TYPE ------------> ".$e);
  }

 ?>

1 个答案:

答案 0 :(得分:0)

好的,就我而言,问题是SELinux

确保这两个变量为ON:

# getsebool -a | grep httpd_can_network_connect
httpd_can_network_connect --> on
httpd_can_network_connect_db --> on

并在未启用时启用它们:

setsebool -P httpd_can_network_connect 1
setsebool -P httpd_can_network_connect_db 1