2009-09-09 36 views
1

我需要與遠程SQL Server 2000數據庫交談。我在本地使用MAMP,我想繼續使用它。然而,我失去了我需要做什麼來增加對PHP與這個數據庫交談的支持。它看起來像PHP中的ODBC或SQL Server函數可以工作,但這些模塊默認情況下不安裝。MAMP:添加ODBC或SQL Server支持

有人可以提供有關如何添加對MAMP中的ODBC或SQL Server的支持的說明嗎?

回答

4

我能夠得到他的工作:

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

摘要:

  1. P ASTE這到你的終端:

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

    (可與OS 10.7)

  2. 打開/usr/local/php5/etc/freetds.conf在文本編輯器並在末尾添加您的MSSQL服務器的條目:

    [MSHOSTNAME] 
    host = mshostname.example.com 
    port = 1433 
    tds version = 8.0 
    
  3. 在您的Sites文件夾中保存一個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); 
    ?>