与MSSQL的PHP​​不安装在centos 7

我想在CentOS Linux系统中通过PHP连接MSSQl服务器。 但是得到低于错误,

Fatal error: Call to undefined function mssql_connect() in /var/www/h..... 

为此,我引用了一些网站,并find了解决办法。 但是这也不起作用。 在这里,我正在尝试安装php5-sybase,但得到一些错误,

 yum install php5-sybase Loaded plugins: fastestmirror, langpacks apt.sw.be_redhat_el2.1_en_mirrors-rpmforge| 1.9 kB 00:00:00 remi-safe | 2.9 kB 00:00:00 One of the configured repositories failed (Unknown), and yum doesn't have enough cached data to continue. At this point the only safe thing yum can do is fail. There are a few ways to work "fix" this: 1. Contact the upstream for the repository and get them to fix the problem. 2. Reconfigure the baseurl/etc. for the repository, to point to a working upstream. This is most often useful if you are using a newer distribution release than is supported by the repository (and the packages for the previous distribution release still work). 3. Disable the repository, so yum won't use it by default. Yum will then just ignore the repository until you permanently enable it again or use --enablerepo for temporary usage: yum-config-manager --disable <repoid> 4. Configure the failing repository to be skipped, if it is unavailable. Note that yum will try to contact the repo. when it runs most commands, so will have to try and fail each time (and thus. yum will be be much slower). If it is a very temporary problem though, this is often a nice compromise: yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true Cannot find a valid baseurl for repo: rpmforge 

如何解决这个问题。

Solutions Collecting From Web of "与MSSQL的PHP​​不安装在centos 7"

要在CentOS上安装SQL server的PHP驱动程序,下面是我建议的:

 sudo su curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo exit sudo ACCEPT_EULA=Y yum install msodbcsql sudo yum install unixODBC-devel yum groupinstall "Development Tools" sudo pecl install sqlsrv pdo_sqlsrv sudo echo "extension= pdo_sqlsrv.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` sudo echo "extension= sqlsrv.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` 

现在你应该可以使用这样一个简单的PHP脚本连接到SQL server:

 <?php $serverName = "localhost"; $connectionOptions = array( "Database" => "SampleDB", "Uid" => "sa", "PWD" => "your_password" ); //Establishes the connection $conn = sqlsrv_connect($serverName, $connectionOptions); if($conn) echo "Connected!" ?> 

提供mssql和pdo_dblib扩展的php-mssql在EPEL存储库中可用。

正如yum错误输出中所解释的那样,您应该禁用rpmforge(可能是apt.sw.be_redhat_el2.1_en_mirrors-rpmforge)

注意:这个扩展是不推荐的,将会在PHP 7中被删除。所以,为了更好的可维护性,我推荐使用PDO驱动。

 yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm yum install php-mssql 

我从EPEL获取了存储库URL并进行了安装。 但我得到了

 [root@localhost tmp]# yum install php5-sybase Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile No package php5-sybase available. Error: Nothing to do [root@localhost tmp]# 

有什么问题?

我不知道是否有人会来这里,但我的问题是,可选rpms没有启用。 我花了一整天在这个卸载和重新安装。 但是后来我在某处发现了这个脚注

注意RHN用户您还需要启用“可选”存储库来使用EPEL包,因为它们依赖于该存储库中的包。 这可以通过为RHN-Classic启用RHEL可选子通道来完成。 对于基于证书的订阅,请参阅“红帽订阅管理指南”。 对于EPEL 7,除了“可选”存储库(rhel-7-server-optional-rpms)之外,还需要启用“extras”存储库(rhel-7-server-extras-rpms)。