phpamazon-web-servicesodbcfreetdsunixodbc

ODBC with FreeTDS PHP Not working via HTTP


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.


Solution

  • 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);