cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure ODBC to work with PHP under linux?

0 Kudos
3,703

I have SQL Anywhere 17.0.0.1062 running with PHP 5.5 under Ubuntu 14.04. It's working fine and I can connect successfully using

$conn = sasql_connect( "Server=mydb;DBN=mydb;UID=DBA;PWD=xxx" );
However, I now want to setup it up to work with ODBC. First I created an ODBC connection with the command:
dbdsn -w mydb -c "Server=mydb;DBN=mydb;UID=DBA;PWD=xxx"
That successfully creates a .odbc.ini file in my home directory (/home/vagrant).
[ODBC Data Sources]
mydb=SQLAnywhere 17.0
[mydb]
UID=DBA
PWD=xxx
ServerName=mydb
Driver=/opt/sqlanywhere17/lib64/libdbodbc17.so
At this point I can use SQL Central and "Connect with an ODBC Data Source". That works.

However using PHP, the statement:

$conn = sasql_connect( "DSN=mydb" );
fails to connect and gives the error
Warning: sasql_connect(): SQLAnywhere: [-95] Parse error: Cannot find .ini file in /usr/share/nginx/html/sasql_test.php on line 3
I've tried defining ODBCHOME=/home/vagrant in /etc/environment (and rebooting), but that doesn't have any effect.

What am I missing here?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

There is something about this that doesn't add up correctly. The .odbc.ini is clearly present since SQL Central can find it and the search for that will automatically include your home directory.

Also since PHP can connect without it this does not seem to related to the environment not being set up correctly; so the generated sa_config.[csh|sh] must have been sourced already.

Maybe this has something to do with they way you launch your PHP runtime?

0 Kudos

Yes, that was it. I'm still new to the way linux uses accounts, but it appears that, by default, php5-fpm launches under www-data. When I changed that to vagrant, it finds the .odbc.ini file and the ODBC connection works.

Thanks for your help.

Answers (0)