[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Connecting to MS Sql Server from php/apache



I have a two virtual machines on my debian unstable desktop machine. One runs windows 7 and has an instance of Microsoft SQL Server Express running on it. The other runs Windows XP and has a version of Apache and Php together with the Microsoft PHP Drivers. All three machines (the host and the two virtual machines) are networked via a virtual bridge, so they all sit in the same subnet and can therefore intercommunicate.

In the WindowsXP machine I have set up a test of PHP talking to the SQL Server database and this works perfectly. ( I mention this because it proves that the database is indeed running and responding to remote requests)

I am now trying to replicate that test on my desktop machine using FreeTDS. However I am struggling to make it work. I have two problems. Firstly I am finding it quite difficult to know precisely which Debian packages I need to install to make it all work, and secondly with the complicated chain of things I don't really know how the error message is telling me what is wrong.

So let me describe the setup in a bit more detail.

1) My local home DNS system identifies the SQL Server machine as "roo.home". The instance of SQL Server is called SQLEXPRESS (so from windows I would access this server as ROO\SQLEXPRESS

2) On my host machine (called kanga.home) I have /etc/freetds/freetds.conf set up (ignoring comment lines) as follows

[global]
    text size = 64512

[roodb]
    host = roo.home
    instance = SQLEXPRESS
    tds version = 7.2

3) I have an apache virtual host setup to recognise ac.home as a web address with the web root set to a place where I have set up index.php as follows

<?php
$dsn = 'dblib:server=roodb';
$user = 'accu_app';
$password = 'xxxx';
try {
    $db = new PDO($dsn, $user, $password);
    $db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
}
catch(PDOException $e) {
    die("Failed with message: " . $e->getMessage());
}
echo "It worked"
?>

When I call this configuration from a web browser I get the following response

Failed with message: SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9)


I have no idea whats wrong, and I find it quite difficult to find some decent instructions of how to set up a dblib connection.

Can anyone help me investigate and solve this problem

--
Alan Chandler
http://www.chandlerfamily.org.uk


Reply to: