简体   繁体   中英

Php does not recognize PDO_DBLIB driver

So I am writting some code so I can access a Microsft SQL Server. The code I am writting is in a Centos 7 machine. I've installed the php mysql and mssql packages but when I run

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.

I've also edited php.ini to include extension=php_mssql.so , and restarted lampp and still got the same output.

When I run the pdo script:

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.

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.

I've found why this didn't work. I installed my lamp stack using 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 .

After the driver is installed CentOS only enables MS SQL Server connections using the console, as default. 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):

# setsebool -P httpd_can_network_connect=1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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