搜索

首页  >  问答  >  正文

MacOS MAMP Pro支持的是Microsoft ODBC Driver 17 for SQL Server。

<p>大佬们帮帮忙,我在Mac上开发PHP应用程序是新手(之前我在Windows上开发),我需要帮助安装MAMP Pro的ODBC Driver 17 for SQL Server。我按照https://github.com/Braineee/microsoft-driver-on-mamp-for-mac/blob/master/README.md上的说明安装了驱动程序,但是出现了驱动程序未找到的错误。<br /><br />在MAMP Pro中已添加了扩展:MAMP Pro<br /><br />文件已复制到MAMP中:MAMP Pro<br /><br />PHP版本:8.1.13</p><p>连接到MSSQL服务器的:</p><p><br /></p> <pre class="brush:php;toolbar:false;">private const SQLdriver = 'ODBC Driver 17 for SQL Server'; private const SQLserver = '192.168.1.12'; private const SQLport = 1433; private const SQLDBName = '?'; private const SQLusername = '?'; private const SQLpassword = '?'; private const SQLparameters = 'TDS_Version=8.0;ClientCharset=UTF-8;'; private const SQLDriverOptions = [PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL]; $dsn = 'DRIVER=' . self::SQLdriver . ';' . 'SERVER=' . self::SQLserver . ';' . (empty(self::SQLport) ? '' : 'PORT=' . self::SQLport . ';') . 'DATABASE=' . ($this->dbType === Marfos::DB_TYPE_MAIN ? self::SQLDBName : self::SQLDBNameTest) . ';' . self::SQLparameters; $this->pdo = new PDO("odbc:" . $dsn . "", self::SQLusername, self::SQLpassword); $this->pdo->setAttribute(PDO::ATTR_CURSOR, PDO::CURSOR_SCROLL);</pre> <p>在Windows的WAMP服务器上连接是正常的。在Mac上,我尝试了所有方法,但是驱动程序未找到。</p><p><br /></p>
P粉594941301P粉594941301478 天前741

全部回复(1)我来回复

  • P粉677684876

    P粉6776848762023-08-09 00:00:59

    phpinfo()显示你已安装了PDO_SQLSRV扩展。不是通过ODBC使用它,而是通过特定的DSN,就像这样:

    $pdo = new PDO("sqlsrv:Server=localhost;Database=testdb", "UserName", "Password");

    回复
    0
  • 取消回复