我想在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
如何解决此问题。
答案 0 :(得分:4)
要在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!"
?>
答案 1 :(得分:0)
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
答案 2 :(得分:0)
我从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]#
问题是什么?
答案 3 :(得分:0)
我不知道是否有人会来这里,但问题是我没有启用可选的rpms。我花了一整天时间进行卸载和重新安装。但后来我在某个地方发现了这个脚注
RHN用户注意事项 您还需要启用“可选”存储库以使用EPEL包,因为它们依赖于该存储库中的包。这可以通过为RHN-Classic启用RHEL可选子通道来完成。有关基于证书的订阅,请参阅“Red Hat订阅管理指南”。对于EPEL 7,除了'可选'存储库(rhel-7-server-optional-rpms)之外,还需要启用'extras'存储库(rhel-7-server-extras-rpms)。
答案 4 :(得分:0)
如果您使用实例连接到外部 sql 服务器,则只需在您的盒子中安装 php-sql 驱动程序。
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
sudo yum install php-sqlsrv
如果您在浏览器上遇到分段错误错误或502网关错误
您可以执行以下步骤来消除此错误:
1. make sure extension loaded are having executable permission.
you can check this information in **/usr/lib64/php/modules**
2. add extension=/usr/lib64/php/modules in your php.ini (**/etc/php.ini**) file
就我而言,我的 php 版本是 7.3,此步骤将解决我的问题。 如果这些步骤没有帮助,您可以检查并升级您的 php 版本。