0

我编写了一个脚本,它的目标是连接访问。这段代码在 cpanel 中,并且 php.ini 设置为启用 odbc。

代码是:

<?php
$mdbFilename="../photogol/photogol.mdb";
$Dsn="Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdbFilename";
$UserName="root";
$Password="";
$connection=odbc_connect($Dsn,$UserName,$Password) or die(odbc_error());
?>

php 解释器在第 6 行捕获错误。

我该怎么办?

4

1 回答 1

1

我在 Ubuntu 14.04 LTS 上,并且在日志文件中有与您相同的错误消息:

/var/log/apache2/error.log

PHP Fatal error:  Call to undefined function odbc_connect() in /var/www/html/test-odbc.php on line 8

要修复此错误,我们只需运行以下命令:

sudo apt-get install php5-odbc

以下是命令输出的示例:

:/etc$ sudo apt-get install php5-odbc
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  php5-odbc
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 30.4 kB of archives.
After this operation, 150 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ trusty-updates/main php5-odbc     amd64 5.5.9+dfsg-1ubuntu4.13 [30.4 kB]
Fetched 30.4 kB in 0s (34.5 kB/s)  
Selecting previously unselected package php5-odbc.
(Reading database ... 217071 files and directories currently installed.)
Preparing to unpack .../php5-odbc_5.5.9+dfsg-1ubuntu4.13_amd64.deb ...
Unpacking php5-odbc (5.5.9+dfsg-1ubuntu4.13) ...
Processing triggers for libapache2-mod-php5 (5.5.9+dfsg-1ubuntu4.13) ...
Setting up php5-odbc (5.5.9+dfsg-1ubuntu4.13) ...

Creating config file /etc/php5/mods-available/odbc.ini with new version
php5_invoke: Enable module odbc for cgi SAPI
php5_invoke: Enable module odbc for cli SAPI
php5_invoke: Enable module odbc for apache2 SAPI

Creating config file /etc/php5/mods-available/pdo_odbc.ini with new version
php5_invoke: Enable module pdo_odbc for cgi SAPI
php5_invoke: Enable module pdo_odbc for cli SAPI
php5_invoke: Enable module pdo_odbc for apache2 SAPI
Processing triggers for libapache2-mod-php5 (5.5.9+dfsg-1ubuntu4.13) ...
于 2015-10-21T22:39:19.003 回答