如何将 ODBC 驱动程序添加到 MAMP 环境?

发布于 2024-07-07 20:22:09 字数 448 浏览 6 评论 0原文

我正在开发使用 php 和 ms access 数据库在 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 没有编译到 PHP 的 MAMP 版本中 (5)。 我也尝试过使用 PDO,并遇到类似的错误。

有人知道怎么修这个东西吗?

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

line 37 looks like this:

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吝吻 2024-07-14 20:22:09

您需要向您的计算机添加一个 ODBC 驱动程序,例如 Actual 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);
        }
    }
  }

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);
        }
    }
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文