我需要与远程 SQL Server 2000 数据库通信。我在本地使用 MAMP,我想继续使用它。但是,我不知道我需要做些什么来添加从 PHP 与该数据库对话的支持。看起来 PHP 中的 ODBC 或 SQL Server 函数都可以工作,但默认情况下不会安装这些模块。
有人可以提供有关如何在 MAMP 中添加对 ODBC 或 SQL Server 的支持的说明吗?
我需要与远程 SQL Server 2000 数据库通信。我在本地使用 MAMP,我想继续使用它。但是,我不知道我需要做些什么来添加从 PHP 与该数据库对话的支持。看起来 PHP 中的 ODBC 或 SQL Server 函数都可以工作,但默认情况下不会安装这些模块。
有人可以提供有关如何在 MAMP 中添加对 ODBC 或 SQL Server 的支持的说明吗?
我能够通过以下方式得到他的工作:
概括:
将其粘贴到您的终端中:
curl -s http://php-osx.liip.ch/install.sh | bash -
(适用于 OS 10.7)
在文本编辑器中打开/usr/local/php5/etc/freetds.conf
并在最后为您的 mssql 服务器添加一个条目:
[MSHOSTNAME]
host = mshostname.example.com
port = 1433
tds version = 8.0
在您的站点文件夹中保存一个 PHP 文件并激活 Web 共享。
<?php
$myUser = "your_name";
$myPass = "your_password";
$myDB = "examples";
//connection to the database
$dbhandle = mssql_connect(MSHOSTNAME, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");
//declare the SQL statement that will query the database
$query = "SELECT id, name, year ";
$query .= "FROM cars ";
$query .= "WHERE name='BMW'";
//execute the SQL query and return records
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";
//display the results
while($row = mssql_fetch_array($result))
{
echo "<li>" . $row["id"] . $row["name"] . $row["year"] . "</li>";
}
//close the connection
mssql_close($dbhandle);
?>
检查这个问题,看起来您需要为您的 PHP 版本获取驱动程序。
这是另一个链接:Connecting to MS SQL server from PHP using MAMP on OSX。