MacOS MAMP Pro支援的是Microsoft ODBC Driver 17 for SQL Server。
P粉594941301
2023-08-08 13:37:00
<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>
phpinfo()顯示你已經安裝了PDO_SQLSRV擴充功能。不是透過ODBC使用它,而是透過特定的DSN,就像這樣: