致命错误:调用未定义的函数odbc_connect()

时间:2013-07-21 11:59:46

标签: php ms-access odbc

我编写了一个脚本,其目标是连接到access。此代码在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行捕获错误。

我该怎么办?

1 个答案:

答案 0 :(得分: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) ...