如何将ODBC驱动程序添加到MAMP环境? [英] How do I add an ODBC driver to a MAMP environment?

查看:75
本文介绍了如何将ODBC驱动程序添加到MAMP环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用php和ms access数据库在PC设置上构建的东西.将应用程序移植到MAMP环境时,我得到

I'm working on something that was built on a PC set-up using php and an ms access database. When I port the app to my MAMP environment, I get

Fatal error: Call to undefined function odbc_connect() in /path/to/index.php on line 37

第37行看起来像这样:

line 37 looks like this:

return odbc_connect("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=myfile.mdb",
"ADODB.Connection", "", "SQL_CUR_USE_ODBC");

似乎odbc尚未编译到MAMP版本的PHP(5)中.我也尝试使用PDO,但遇到类似的错误.

It seems like odbc isn't compiled into the MAMP version of PHP (5). I also tried using PDO, and got similar errors.

有人知道如何解决这个问题吗?

Anyone know how to fix this?

推荐答案

您将需要添加ODBC驱动程序,例如 Actual ODBC 到您的计算机上,也就是说,如果您的PHP版本符合任何ODBC功能(应该具有),但是如果没有,则需要安装具有适当支持的其他版本.我很幸运使用 MacPorts 安装PHP.但是请注意,仍然缺少一些功能,您可能希望为这些功能编写包装器,如下所示:

You will need to add an ODBC driver like Actual ODBC to your machine, that is if your version of PHP had any ODBC functionality complied in, which it should have, but if not you'll need to install a different version with the appropriate support. I've had good luck with using MacPorts to install PHP. But note that there are still some functions missing that you may expect you'll have to write wrappers for these functions like so:

  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);
        }
    }
  }

这篇关于如何将ODBC驱动程序添加到MAMP环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆