• PHP Access To An MSSQL Database From Debian LENNY With ODBC And FreeTDS

    2009-12-25

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
    http://sunhuang.blogbus.com/logs/54965443.html

    1. #apt-get install tdsodbc libct3 unixodbc php5-odbc freetds-dev php5-sybase
    2. build DSN template (odbcinst)
      1. ODBC Driver registration:

           #vim /etc/freetds/tds.driver.template

    [TDS]
    Description     = FreeTDS Driver for Linux & MSSQL on Win32
    Driver          = /usr/lib/odbc/libtdsodbc.so
    Setup           = /usr/lib/odbc/libtdsS.so
      2.DSN register#odbcinst -i -d -f /etc/freetds/tds.driver.template
      #vim /etc/freetds/tds.dsn.template
    [DSN_NAME]
    Description     = Test to freeTDS
    Driver          = TDS
    Trace           = No
    Database        = DefaultDatabase [replace with your database name]
    Server          = mysqlserver.inter.net [replace with your SQL server's host]
    Port            = 5050 [replace with the port that SQL is listening on]

              3 Register above to unixodbc

                  #odbcinst -i -d -f /etc/freetds/tds.driver.template

                  #odbcinst -i -s -f /etc/freetds/tds.dsn.template

                  #mv /etc/odbc.ini /etc/odbc.ini.bak  [in case you had others]

                  #cp /root/.odbc.ini /etc/odbc.ini

                  #vim  /etc/php5/apache2/php.ini ------------copy and paste below

                 extension = odbc.so
       #/etc/init.d/apache2 restart
    4. Testing
        #isql -v DSN_NAME username password
       php sample code
    <?php
    
    # connect to a DSN "DSN_NAME" with a user "Bob" and password "Marley"
    $connect = odbc_connect("DSN_NAME", "Bob", "Marley");
    
    # query the users table for all fields
    $query = "SELECT * FROM users";
    
    # perform the query
    $result = odbc_exec($connect, $query);
    
    # fetch the data from the database
    while(odbc_fetch_row($result)) {
    $field1 = odbc_result($result, 1);
    $field2 = odbc_result($result, 2);
    print("$field1 $field2\n");
    }
    
    # close the connection
    odbc_close($connect);
    
    ?>

    收藏到:Del.icio.us




    评论

  • 换位思考。我的博客也是关于watir方面的,www.sdgz.cn