ODBC with FreeTDS PHP Not working via HTTP

999 views Asked by At

I have got FreeTDS, unixODBC and ODBC enabled on PHP. It all seems to work great. I could connect via iSQL command line.

For some reason PHP is not able to work when accessed via HTTP.

For example. via command line if I run php index.php (where index.php connects via ODBC) it works well.

but the same code when accessed via HTTP, returns

Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect

Could this be a case of some permission

Thanks in advance

Here is the connection code

$connect = odbc_connect("DSNNAME", "USERNAME", "PASSWORD") or die('e'); 

I have changed the credentials. But the code works fine when I run it via PHP command through SSH via Terminal. But when I run it through HTTP it does not.

Also on SSH I am NOT running it via root user. I am using ec2 AWS - and ran SSH via ec2-user (which is the default)

I feel 'apache' user does not have permission to something which I am unaware of.

2

There are 2 answers

0
SG_ On BEST ANSWER

You can add the DSN from the PHP source code like this

 $dsn = "Driver=FreeTDS;Server=192.168.1.17;Port=1433;Database=mydb;TDS_Version=7.2;";
 $Connection = odbc_connect($dsn,$user,$pass);
0
user16538051 On

2021 - BACK TO THE FUTURE:

I know that this post is old, but my reply can point a desperate soul in the right direction:

  1. You are using odbc and the command "isql" works just fine
  2. You are using FreeTDS and the command "tsql" works just fine
  3. Trouble is running the php scripts that have calls to odbc via FreeTDS -> keeps giving errors

Kindly read: https://www.linuxquestions.org/questions/blog/tix-592494/freettds-libiodbc-iodbc-php-7-4-21-on-slackware-current-5-13-5-38621/