MAMP: Adding ODBC or SQL Server support

与世无争的帅哥 提交于 2019-12-10 11:42:14

问题


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?


回答1:


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.




回答2:


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);
     ?>
    


来源:https://stackoverflow.com/questions/1400908/mamp-adding-odbc-or-sql-server-support

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