I am trying to connect to a remote MSSQL server using the platforms listed in the title. I have FreeTDS and all the relevant ODBC packages installed. Here is my freetds.conf:
# $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $
#
# This file is installed by FreeTDS if no file by the same
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# see the freetds.conf manpage "man freetds.conf".
# Global settings are overridden by those in a database
# server specific section
[global]
# TDS protocol version
; tds version = 4.2
# Whether to write a TDSDUMP file for diagnostic purposes
# (setting this to /tmp is insecure on a multi-user system)
; dump file = /tmp/freetds.log
; debug flags = 0xffff
# Command and connection timeouts
; timeout = 10
; connect timeout = 10
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
[DEVSQL]
host = x.x.x.x
instance = DEVSQL
tds version = 8.0
Here is my odbc.ini:
[ODBC Data Sources]
DEVSQL = FreeTDS Connection Server
[DEVSQL]
Description = MSSQL Server
Driver = freetds
ServerName = DEVSQL
Database = test
TDS_Version = 8.0
Here is my PHP code:
<?php
$dbname = "test";
$servername = "DEVSQL";
$username = "myuser";
$password = "mypassword";
try{
$db = new PDO('odbc:Driver=FreeTDS; Server='.$servername.'; Database='.$dbname.'; UID='.$username.'; PWD='.$password.';');
Database='.$dbname.'; UID='.$username.'; PWD='.$password.';');
}
catch(PDOException $exception){
die("Unable to open database.<br />Error message:<br /><br />$exception.");
}
echo '<h1>Successfully connected!</h1>';
?>
I am able to connect just fine using the following commands in the terminal:
TDSVER=8.0 tsql -S devsql -U myuser -P mypassword
as well as:
isql -v devsql myuser mypassword
But when I browse to index.php in FireFox I get the following error:
exception 'PDOException' with message 'SQLSTATE[08001] SQLDriverConnect: 0 [unixODBC][FreeTDS][SQL Server]Unable to connect to data source' in /var/www/html/index.php:16 Stack trace: #0 /var/www/html/index.php(16): PDO->__construct('odbc:Driver=Fre...') #1 {main}.
Any help much appreciated! Alos, if anyone has a better way to connect to sql server from a linux box using php, I'm all ears. Thanks again!
EDIT: I forgot to mention: Ubuntu and Apache are running inside a VM instance on a Win7 host. The Win7 environment on that same machine is where the SQL server is running. I'm not sure if that's relevant since they are communicating just fine, but thought I'd throw it out there.