Search code examples
phpcakephpphp-extensionpecldbase

DBase in CakePHP?


How can I use DBase in CakePHP (v3.1)? I've already installed it with PECL (v5.1.1) and it works fine with plain php, but when I run dbase_create() in CakePHP it gives me an error:

Call to undefined function App\Controller\dbase_open()

I've included the extension in /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini


Solution

  • Here are the debug steps taken to fix the problem:

    1. The error message says the function App\Controller\dbase_create() does not exist. What we'd expect is the function dbase_create(), so the error message indicates PHP is looking in the wrong namespace. Changing the function call to \dbase_create() caused PHP to look in the global namespace.

    2. PHP still gave an error message, this time saying the function dbase_create() does not exist. That at least indicates that PHP is now looking in the right place, but the function also doesn't exist in the global namespace.

    3. The php.ini files were modified, but Apache loads all configuration files for its modules when it starts. To ensure changes are loaded, Apache needs to be restarted when the php.ini file is changed. Restart Apache to load the new version of the file.

    4. After restarting Apache, the function still does not exist. Let's make sure the module is loaded properly. Call the phpinfo() function and check its output for anything related to DBase. This gave an interesting result: a separate PHP file with just phpinfo() indicated that DBase 5.1.1 was loaded, but calling phpinfo() from the CakePHP application did not output anything related to DBase.

    5. CakePHP was running as its own server. Like Apache, the php.ini file is loaded when that server starts, so make sure to restart that server when the file changes. This fixed the issue, after restarting the CakePHP server the dbase_create() function was available.