How do I add an ODBC driver to a MAMP environment?

微笑、不失礼 提交于 2019-12-02 05:53:54

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);
        }
    }
  }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!