سؤال

أريد التحدث عن بعد SQL Server 2000 البيانات الخاصة بنا.يمكنني استخدام MAMP محليا وأود أن الاستمرار في استخدامه.ومع ذلك, أنا فقدت ما أريد القيام به لإضافة دعم يتحدث إلى قاعدة البيانات هذه من PHP.يبدو إما ODBC أو SQL Server وظائف في PHP ، ولكن هذه الوحدات ليست مثبتة بشكل افتراضي.

يمكن للشخص تقديم إرشادات حول كيفية إضافة دعم إما ODBC أو SQL Server في MAMP?

نصائح أخرى

وكنت قادرا على الحصول على العمل من خلال:

  1. باستخدام Liip واحد خط PHP وحدة اباتشي المثبت
  2. تكوين freetds.الملف conf
  3. كتابة بعض PHP الاتصال إلى قاعدة بيانات mssql

موجز:

  1. لصق هذا إلى محطة الخاص بك:

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

    (يعمل مع نظام التشغيل OS 10.7)

  2. فتح /usr/local/php5/etc/freetds.conf في محرر النص و إضافة إدخال الخاص بك mssql server في النهاية:

    [MSHOSTNAME]
    host = mshostname.example.com
    port = 1433
    tds version = 8.0
    
  3. حفظ ملف PHP في مواقع مجلد وتفعيل مشاركة ويب.

    <?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);
     ?>
    
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top