MAMP: Add ODBC or SQL Server Support

I need to talk to a remote SQL Server 2000 database. I am using MAMP locally and I would like to continue using it. However, I lost what I need to do to add support for communicating with this database with PHP. It looks like either the ODBC or SQL Server functions in PHP will work, but these modules are not installed by default.

Can someone provide instructions on adding ODBC or SQL Server support to MAMP?

+1
sql-server mamp odbc
source share
2 answers

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

Here is another link: Connecting to MS SQL Server with PHP using MAMP on OSX .

+2
source share

I managed to get it working:

Summary:

  • Paste this into your terminal:

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

    (works with OS 10.7)

  • 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 
  • Save the PHP file in the Sites folder and activate website 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); ?> 
+4
source share

All Articles