题
我正在研究使用php和ms访问数据库在PC设置上构建的东西。当我将应用程序移植到我的MAMP环境时,我得到了
Fatal error: Call to undefined function odbc_connect() in /path/to/index.php on line 37
第37行看起来像这样:
return odbc_connect("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=myfile.mdb",
"ADODB.Connection", "", "SQL_CUR_USE_ODBC");
似乎odbc没有编译到MAMP版本的PHP(5)中。我也尝试过使用PDO,也遇到了类似的错误。
任何人都知道如何解决这个问题?
解决方案
您需要将 Actual ODBC 等ODBC驱动程序添加到您的计算机上,即您的版本PHP有任何ODBC功能,它应该具有,但如果没有,你将需要安装具有适当支持的不同版本。我很幸运使用 MacPorts 来安装PHP。但请注意,仍然有一些函数缺失,您可能希望您必须为这些函数编写包装器,如下所示:
if(!function_exists("odbc_fetch_array"))
{
function odbc_fetch_array($aResult,$anAssoc=false)
{
# Out of rows? Pass back false!
if(!odbc_fetch_row($aResult)) return false;
$theRow = array();
# Build up array
$theNumFields = odbc_num_fields($aResult);
$theLimit = $theNumFields+1;
for($i=1; $i<$theLimit; $i++)
{
# WARNING: Starts our index at 0, unlike standard ODBC which starts at 1
$theRow[odbc_field_name($aResult, $i)] = odbc_result($aResult, $i);
if(!$anAssoc) $theRow[$i-1] = $theRow[odbc_field_name($aResult, $i)];
}
return $theRow;
}
}
if(!function_exists("odbc_fetch_assoc"))
{
function odbc_fetch_assoc($aResult)
{
if (DIRECTORY_SEPARATOR == '/') // call local function on MACs
{
return odbc_fetch_array($aResult,true);
}
else // call built in function on Windows
{
return odbc_fetch_array($aResult);
}
}
}
不隶属于 StackOverflow