未在centos 7中安装MSSQL的PHP

未在centos 7中安装MSSQL的PHP,php,sql-server,linux,centos,Php,Sql Server,Linux,Centos,我想在CentOS Linux系统中通过PHP连接MSSQl服务器。但在误差以下 Fatal error: Call to undefined function mssql_connect() in /var/www/h..... 为此,我参考了一些网站并找到了解决方案。但这也不起作用。 在这里,我尝试安装php5 sybase,但出现了一些错误 yum install php5-sybase Loaded plugins: fastestmirror, langpacks apt.sw.be

我想在CentOS Linux系统中通过PHP连接MSSQl服务器。但在误差以下

Fatal error: Call to undefined function mssql_connect() in /var/www/h.....
为此,我参考了一些网站并找到了解决方案。但这也不起作用。 在这里,我尝试安装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
yum安装php5-sybase
加载的插件:FastTestMirror、langpacks
apt.sw.be_redhat_el2.1_en_mirrors-rpmforge | 1.9kb 00:00:00
remi safe | 2.9KB 00:00:00
其中一个配置的存储库失败(未知),
而且yum没有足够的缓存数据继续。在这一点上,唯一的
百胜可以做的安全事情就是失败。有几种方法可以“修复”此问题:
1.联系上游的存储库,让他们解决问题。
2.为存储库重新配置baseurl/etc,以指向工作
上游如果您使用的是较新的
存储库(以及
上一个发行版的包仍然有效)。
3.禁用存储库,以便默认情况下yum不会使用它。那么百胜将
只需忽略存储库,直到您再次永久启用或使用它
--临时使用的enablerepo:
yum配置管理器--禁用
4.如果失败的存储库不可用,请将其配置为跳过。
请注意,yum将尝试联系repo。当它运行大多数命令时,
因此,每次都必须尝试失败(因此,百胜将是非常重要的)
较慢)。如果这是一个非常暂时的问题,这通常是一个很好的解决方案
妥协:
yum config manager--save--setopt=.skip_if_unavailable=true
找不到repo:rpmforge的有效baseurl

如何解决此问题。

php mssql,它提供和扩展在存储库中可用

如yum error output中所述,应该禁用rpmforge(可能还有apt.sw.be_redhat_el2.1_en_mirrors-rpmforge)

注意:此扩展已弃用,将在PHP7中删除。因此,为了更好的可维护性,我建议使用PDO驱动程序

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

php-mssql,它提供和扩展,可在存储库中找到

如yum error output中所述,应该禁用rpmforge(可能还有apt.sw.be_redhat_el2.1_en_mirrors-rpmforge)

注意:此扩展已弃用,将在PHP7中删除。因此,为了更好的可维护性,我建议使用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]#

问题是什么?

我从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]#

问题是什么?

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

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

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

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

要在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!"
?>

要在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!"
?>


我从EPEL获得了存储库URL并安装了它。但我犯了个错误。[root@localhosttmp]#yum安装php5-sybase加载的插件:fastestmirror,langpacks从缓存的主机文件加载镜像速度没有可用的php5-sybase包。错误:无事可做[root@localhosttmp]#阅读我的答案,该包是php mssql,而不是php5 sybaseNo luck。得到同样的问题。。。我正在使用Centos 7和PHP5.4,但不知道会发生什么,这对其他人都适用,包就在那里:我从EPEL获得了存储库URL并安装了。但我犯了个错误。[root@localhosttmp]#yum安装php5-sybase加载的插件:fastestmirror,langpacks从缓存的主机文件加载镜像速度没有可用的php5-sybase包。错误:无事可做[root@localhosttmp]#阅读我的答案,该包是php mssql,而不是php5 sybaseNo luck。得到同样的问题。。。我使用的是Centos 7和PHP 5.4,但不知道会发生什么,这对其他人都有效,软件包也在那里:我试图在我的VPS上安装它,但当我得到命令“sudo pecl install sqlsrv pdo_sqlsrv”时,我一直遇到错误“pecl:command not found”。我试图在我的VPS上安装它,但是当我看到命令“sudopecl安装sqlsrv pdo_sqlsrv”时,我一直遇到这个错误“pecl:commandnotfound”。