Comments on PHP Access To An MSSQL Database From Debian Etch With ODBC And FreeTDS

PHP Access To An MSSQL Database From Debian Etch With ODBC And FreeTDS This assumes you already have Apache2 and PHP5 set up properly on your system. My efforts to get this connection working were compiled from information found at www.unixodbc.org and www.freetds.org. These steps worked for me with an Apache2 web server with php5 running on Debian Etch stable in October of 2007. The SQL server is running Microsoft SQL 2005 on a Windows 2003 Server OS.

8 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By:

odbcinst creates User DSN's by default. You can instruct it to create a System DSN directly by defining the option "-l" in the command line:

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

Tom

By: Marcel

Hi.

Nice tutorial though.

I have one question:
I have set up everything very straight away and via
isql and tsql I get instantly access to the remote database without any problem.

But when I try it via PHP I get:
odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect

I have investigated this topic and there are a lot of people having the same problem, but there are no clear solutions out there.

The funny thing is that I have everything configured.

I do not have any clue what's going wrong. Does anybody have a clue?
THX a lot in advance...

Cheers.
M.

By: Anonymous

you could probably try to replace "DSN_NAME" in the above example with the name of the odbc Datasource you're trying to connect to. In my case the DSN has to be named "sugarcrm" because sugarcrm is configured in a way it expects a odbc datasource named sugarcrm.

By: Anonymous

One thing I found:  odbc.ini is picky about spaces.  Don't indent.

By: Anonymous

worked to perfection
thanks!

 funciono a la perfeccion
gracias!

By: Anonymous

does not work: odbc.so does not exist... -> Fatal error: Call to undefined function mssql_connect() in /var/www/test.php on line 4

By: Pudrik

You also need to edit /etc/freetds/freetds.conf

add following lines at the end

[Server80]
        host = serverip
        port = 1433
        tds version = 8.0
 

 

 Run

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

" isql -v DSN_NAME username password  " should now work for mssql 8.0 server.

By: Gabor

Has anyone found a solution for the problem mentioned by Marcel below? I have CentOS 7.8 with an ODBC datasource and MSODBC17 driver, and I am able to connect to the SQL Server 17 instance both with SQLCMD and with ISQL. I also have a C++ application using the same driver, also able to connect fine. However, PHP 7.4 app shows network connection error ("A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible."). I tried the no-space trick also mentioned below, I removed all spaces from the Description field and the driver name also from odbcinst.ini, and from the Description in the odbc.ini also (and also using the Driver name with no spaces in it).