尽管已正确安装,sqlsrv 仍无法运行

尽管已正确安装,sqlsrv 仍无法运行

我已经(再次)使用 pecl 为 Ubuntu 18 安装了 sqlsrv,但由于某种原因未找到驱动程序。

这是我收到的错误could not find driver

以下是我遵循的步骤:

$ sudo apt-get remove php-common
$ sudo apt-get autoremove
$ sudo apt-get install php-fpm php-mbstring php-zip php-mysql php-sqlite3 php-dev php-pear php-xml


$ sudo pecl uninstall sqlsrv
$ sudo pecl uninstall pdo_sqlsrv

$ sudo pecl install sqlsrv
$ sudo pecl install pdo_sqlsrv

我创建了文件 sqlsrv.ini,内容如下:

extension=pdo_sqlsrv.so
extension=sqlsrv.so

并将其复制/etc/php/7.2/cli//etc/php/7.2/fpm/

PHP 代码如下:

$host = "station\SQL, port"; //azure
$db = "dbname";
$user = "user";
$pass = "pass";

try {
    $conn = new PDO("sqlsrv:Server=$host;Database=$db;LoginTimeout=60", $user, $pass);
}
catch (Exception $e) {
    echo $e->getMessage();
}

当尝试使用 CLI 列出模块时,php -m | grep sql我没有在已加载模块列表中找到 sqlsrv 模块:

mysqli
mysqlnd
pdo_mysql
pdo_sqlite
sqlite3

或者php --ri pdo_sqlsrv返回Extension 'pdo_sqlsrv' not present.

odbcinst -j返回:

unixODBC 2.3.4
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

dpkg-query -L libodbc1返回:

/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libodbc.so.2.0.0
/usr/lib/x86_64-linux-gnu/libodbccr.so.2.0.0
/usr/lib/x86_64-linux-gnu/odbc
/usr/lib/x86_64-linux-gnu/odbc/libnn.so
/usr/share
/usr/share/doc
/usr/share/doc/libodbc1
/usr/share/doc/libodbc1/NEWS.Debian.gz
/usr/share/doc/libodbc1/changelog.Debian.gz
/usr/share/doc/libodbc1/copyright
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/libodbc1
/usr/lib/x86_64-linux-gnu/libodbc.so.1
/usr/lib/x86_64-linux-gnu/libodbc.so.2
/usr/lib/x86_64-linux-gnu/libodbccr.so.1
/usr/lib/x86_64-linux-gnu/libodbccr.so.2

答案1

相关内容