user2604098
user2604098

Reputation: 97

Fatal error: Call to undefined function odbc_connect()

I've written a script that its goal is to connect to access.This code is in cpanel and php.ini is set to enable the odbc.

The code is :

<?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 interpreter catches error on line 6.

What should I do?

Upvotes: 0

Views: 4259

Answers (1)

Happy
Happy

Reputation: 825

I am on Ubuntu 14.04 LTS, and has the same error message as you in log file:

/var/log/apache2/error.log

Saying

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

To fix this error we can simply run the following command:

sudo apt-get install php5-odbc

Here is an example of the command output:

:/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) ...

Upvotes: 1

Related Questions