MacOS 10.13重建PHP7添加ODBC扩展异常及odbc_connect未定义求助
Hey there, let's tackle your ODBC and PHP7 issues step by step—you've got two main problems here, so we'll break them down one by one:
1. Fixing the Call to undefined function odbc_connect() Error
This error means PHP isn't loading the ODBC extension. Let's start with the simplest checks first:
Verify if ODBC is enabled in PHP
Create a quickphpinfo.phpfile in your web root with:<?php phpinfo(); ?>Access it in your browser and search for "ODBC". If you don't see any ODBC-related sections, the extension isn't loaded.
If you installed PHP via Homebrew, you can install the ODBC extension using PECL:
pecl install odbcWhen prompted for the ODBC library path, use
/usr/local(for Homebrew's unixODBC) or/Library/ODBC(for ActualTech's driver files).Update php.ini to load the extension
Find your activephp.inifile (check the "Loaded Configuration File" line in phpinfo), then add this line:extension=odbc.soFor PHP 7.4+, you can omit the
.sosuffix:extension=odbc. Restart Apache to apply changes:sudo apachectl restartValidate ActualTech ODBC Driver Setup
Open ActualTech's ODBC Manager, confirm your FileMaker DSN is configured correctly, and run a test connection to ensure it works. Also, double-check that the driver architecture matches your PHP build (both should be 64-bit, which is default on High Sierra).
2. Resolving the "Makefile is not as expected" Error When Compiling PHP7
Manual PHP compilation issues often stem from leftover build files, missing dependencies, or incorrect configure flags. Try these steps:
Clean up old build artifacts
Navigate to your PHP source directory and wipe previous builds:make clean make distcleanThis removes outdated Makefiles and intermediate files that might be causing conflicts.
Install required dependencies
Compiling PHP's ODBC support needs unixODBC (even with ActualTech's driver). Install it via Homebrew:brew install unixodbcAlso ensure you have other core PHP dependencies like
libxml2,openssl, andaprinstalled—Homebrew usually handles these, but it's worth checking.Configure PHP with correct ODBC flags
Run the configure script with explicit ODBC path and Apache integration. For example:./configure --prefix=/usr/local/php7 --with-apxs2=/usr/sbin/apxs --with-odbc=unixODBC--prefixsets where PHP will be installed--with-apxs2links to your Apache'sapxs(default path on High Sierra is/usr/sbin/apxs)- If you want to use ActualTech's driver directly, replace
unixODBCwith/Library/ODBC
Recompile and install
After a successful configure run, rebuild PHP:make sudo make installIf you still get errors, check the
configureoutput log for missing library warnings—adjust your flags or install the missing dependencies accordingly.
3. CodeIgniter-Specific Checks
Since you're using CodeIgniter, make sure your database config is set up for ODBC:
- Open
application/config/database.phpand verify these settings:$db['default'] = array( 'dsn' => 'YOUR_FILEMAKER_DSN_NAME', // Match the DSN from ODBC Manager 'username' => 'your_filemaker_username', 'password' => 'your_filemaker_password', 'dbdriver' => 'odbc', 'dbprefix' => '', 'pconnect' => FALSE, 'db_debug' => TRUE, // Enable debug to catch connection issues 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), 'save_queries' => TRUE ); - Ensure the CodeIgniter ODBC driver files (
system/database/drivers/odbc/) are intact and unmodified.
内容的提问来源于stack exchange,提问作者Giuseppe Capoluongo

