PHP 通过 FreeTDS 链接 MSSQL

PHP 通过 FreeTDS 链接 MSSQL

TONYLABS 11 Feb, 2014
Share:

安装 FreeTDS 和 PHP MSSQL 扩展

sudo apt-get install freetds-common freetds-bin unixodbc php5-sybase

重新启动 Apache

sudo /etc/init.d/apache2 restart

测试 FreeTDS

tsql -H your.server.name -p 1433 -U yourusername -P yourpassword -D yourdatabasename

配置 FreeTDS

sudo nano /etc/freetds/freetds.conf 在最后一行添加: [yourserver] host = your.server.name port = 1433 tds version = 8.0

通过已配置文件服务器名测试 FreeTDS

tsql -S yourserver -U yourusername -P yourpassword -D yourdatabasename

在 PHP 代码中测试

$link = mssql_connect('yourserver', 'yourusername', 'yourpassword'); if (!$link) {  die('Unable to connect!'); } if (!mssql_select_db('yourdatabasename', $link)) {  die('Unable to select database!'); } $result = mssql_query('SELECT * FROM yourtable'); while ($row = mssql_fetch_array($result)) {  var_dump($row); } mssql_free_result($result);

Like what you're reading? Subscribe to our top stories.

We will continue to update Front; if you have any questions or suggestions, please contact us!

Follow us on Medium, Twitter, Facebook, YouTube, and Dribbble.

Image Description
Written by

Hanna Wolfe

I create advanced website builders made exclusively for web developers.

3 Comments

  • Image Description
    Dave Austin 1 day ago

    As a Special Education teacher this resonates so well with me. Fighting with gen ed teachers to flatten for the students with learning disabilities. It also confirms some things for me in my writing.

    Reply
    • Image Description
      Hanna Wolfe 1 day ago

      Love it Dave! We're all about keeping it up.

      Reply
  • Image Description
    Christina Kray 2 days ago

    Since our attention spans seem to be shrinking by the day — keeping it simple is more important than ever.

    Reply

Post a comment

Stay in the know

Get special offers on the latest developments from Front.