简体   繁体   English

PHP无法识别PDO_DBLIB驱动程序

[英]Php does not recognize PDO_DBLIB driver

So I am writting some code so I can access a Microsft SQL Server. 因此,我正在编写一些代码,以便可以访问Microsft SQL Server。 The code I am writting is in a Centos 7 machine. 我编写的代码在Centos 7机器中。 I've installed the php mysql and mssql packages but when I run 我已经安装了php mysql和mssql软件包,但是当我运行时

echo "<pre>", print_r(PDO::getAvailableDrivers()), "</pre>";

I get the following output: 我得到以下输出:

Array
(
   [0] => mysql
   [1] => pgsql
   [2] => sqlite
)

I've restarted the lampp and still got the same result. 我重新启动了lampp,仍然得到了相同的结果。

I've also edited php.ini to include extension=php_mssql.so , and restarted lampp and still got the same output. 我还编辑了php.ini以包括extension=php_mssql.so ,并重新启动了lampp,仍然得到相同的输出。

When I run the pdo script: 当我运行pdo脚本时:

try
{
    $con = new PDO("dblib:host=".$db_addr.";dbname=".$db_name.";charset=utf8", '".$db_usr."', '".$db_pass."');
    $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
    echo "ERROR: ". $e->getMessage();
    die(); 
}

I always get: 我总是得到:

ERROR: could not find driver

I relalise that this needs to be configured in the php.ini , but the the drivers that are output are commented out of php.ini , hence I am quite confused. 我relalise,要在配置此需求php.ini ,但是输出驱动器被注释掉的php.ini ,所以我很困惑。

Can someone guide me in the proper direction? 有人可以指引我正确的方向吗?

EDIT: I've followed @jap1968 answer in here , but I got stuck at where I am now. 编辑:在这里 ,我一直遵循@ jap1968的答案,但是我被困在现在的位置。

I've found why this didn't work. 我发现了为什么这行不通。 I installed my lamp stack using xampp. 我使用xampp安装了灯架。 So I had trouble getting the extra modules. 所以我很难获得额外的模块。

To fix it I reinstaled an apache server (httpd), mysql (MariaDB) and php and I then managed to add the driver I needed, following @jap1968's answer in here . 为了修复它,我重新安装了Apache服务器(httpd),mysql(MariaDB)和php,然后按照@ jap1968的回答在添加了所需的驱动程序。

After the driver is installed CentOS only enables MS SQL Server connections using the console, as default. 安装驱动程序后,默认情况下,CentOS仅使用控制台启用MS SQL Server连接。 So when I accessed my script using the browser, I got an Error message saying the server was unavailable. 因此,当我使用浏览器访问脚本时,收到一条错误消息,指出服务器不可用。

To have access through the browser you need to use (I ran this with root permissions, also it may take some seconds): 要通过浏览器进行访问,您需要使用它(我以root权限运行了它,也可能需要几秒钟):

# setsebool -P httpd_can_network_connect=1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM