Run a query from php / ubuntu on sql server

Submitted by barnettech on

(note to run stored procs on sql server from php/ubuntu there's another tech note I've posted)

http://jamesrossiter.wordpress.com/2011/03/08/connecting-to-microsoft-s…

sudo apt-get install php5-sybase
sudo /etc/init.d/apache2 restart

now here is the php file that works:


<?php
ini_set('display_errors', 1);
$server = 'server_name;
$link = mssql_connect($server, 'username', 'password');
if (!$link) {die('

Something went wrong while connecting to MSSQL '); } else { $selected = mssql_select_db('pubs', $link) or die('cant connect the sql server '.mssql_error()); echo "connected to databasename
"; $result = mssql_query("SELECT COUNT(*) as count FROM authors"); while($row = mssql_fetch_array($result)) echo $row["count"] . "
"; } ?>