MAMP:添加 ODBC 或 SQL Server 支持

发布于 2024-08-04 11:20:54 字数 198 浏览 2 评论 0原文

我需要与远程 SQL Server 2000 数据库通信。我在本地使用 MAMP,并且想继续使用它。但是,我不知道需要做什么来添加从 PHP 与该数据库通信的支持。看起来 PHP 中的 ODBC 或 SQL Server 函数都可以工作,但默认情况下不会安装这些模块。

有人可以提供有关如何在 MAMP 中添加对 ODBC 或 SQL Server 的支持的说明吗?

I need to talk to a remote SQL Server 2000 database. I use MAMP locally and I would like to continue using it. However, I'm lost as to what I need to do to add support for talking to this database from PHP. It looks like either the ODBC or SQL Server functions in PHP will work, but those modules aren't installed by default.

Can someone provide instructions on how to add support for either ODBC or SQL Server in MAMP?

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

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

发布评论

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

评论(2

小姐丶请自重 2024-08-11 11:20:54

我能够通过以下方式让他工作:

  1. 使用 Liip 的一行 PHP Apache 模块安装程序
  2. 配置 freetds.conf 文件
  3. 编写一些 PHP 来连接到 mssql 数据库

摘要:

  1. 将其粘贴到您的终端中:

    curl -s http://php-osx.liip.ch/install。嘘 | bash-

    (适用于 OS 10.7)

  2. 在文本编辑器中打开 /usr/local/php5/etc/freetds.conf 并在末尾添加您的 mssql 服务器的条目:

    <前><代码>[MSHOSTNAME]
    主机 = mshostname.example.com
    端口=1433
    TDS 版本 = 8.0

  3. 保存 PHP将文件保存在“站点”文件夹中并激活网络共享。

    <前><代码>” 。 $numRows 。 “ 排” 。 ($numRows == 1 ? "" : "s") 。 “已返回”;

    //显示结果
    while($row = mssql_fetch_array($result))
    {
    回显“

  4. ” 。 $行[“id”]。 $行[“名称”]。 $行[“年份”] 。 “
  5. ”;
    }
    //关闭连接
    mssql_close($dbhandle);
    ?>

I was able to get his working by:

  1. Using Liip's one line PHP Apache Module Installer
  2. Configuring the freetds.conf file
  3. Writing some PHP to connect to the mssql database

Summary:

  1. Paste this into your terminal:

    curl -s http://php-osx.liip.ch/install.sh | bash -

    (works with OS 10.7)

  2. Open /usr/local/php5/etc/freetds.conf in a text editor and add an entry for your mssql server at the end:

    [MSHOSTNAME]
    host = mshostname.example.com
    port = 1433
    tds version = 8.0
    
  3. Save a PHP file in your Sites folder and activate Web Sharing.

    <?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);
     ?>
    
如果没有你 2024-08-11 11:20:54

检查这个问题,看起来就像您需要获取适合您的 PHP 版本的驱动程序一样。

这是另一个链接: 在 OSX 上使用 MAMP 从 PHP 连接到 MS SQL 服务器

Check this question out, looks like you need to get a driver for your version of PHP.

Here is another link: Connecting to MS SQL server from PHP using MAMP on OSX.

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