E
E
Evgen2015-12-27 15:01:02
PHP
Evgen, 2015-12-27 15:01:02

How to correctly set environment variables for correct operation of odbc from PHP?

Hello!
There is a script that creates a class object, let's call it CPConnect.
In this class, in the constructor, the following happens:

private function set_openedge_env() {
            putenv("DLC=/usr/dlc");
            putenv("ODBCINST=/home/odbcinst.ini");
            putenv("ODBCINI=/home/odbc.ini");
            putenv("LD_LIBRARY_PATH=/usr/dlc/odbc/lib");
        }

function __construct() {
            $this->set_openedge_env();
            if ($this->conn_id = odbc_connect($this->dsn, $this->db_user, $this->db_pass, SQL_CUR_USE_ODBC)) {

            } else {
                throw new Exception("Сonnect error. " . $this->conn_id);
            }
        }

Here is a piece of code from the script in which this constructor is called
$progressConnect = new CPConnect();
echo getenv("DLC");

At the same time, if you run it from the Ubuntu console, you get the following result on the screen:
/usr/dlc

If you run from a web browser, then the screen is empty. In this case, the following error occurs in the logs:
odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect

Googling didn't turn up much specifically in my case, except maybe this link , this one, and this one . On the first link the situation is not solved, on the second and third so far too.
Apache has a different user than the one I'm running from on the command line. From everything described, I come to the conclusion that environment variables are simply not set for the Apache user, because of this the script does not work.
All phpinfo()necessary variables are displayed in, safemode is disabled.
Setting up /etc/environment and setting envars for Apache also didn't work.
How to cure it?
Interestingly, on a neighboring server with the same php.ini settings, everything works as it should.
It is possible that the Apache user lacks some rights, but it is not yet clear which ones.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgen, 2015-12-28
@EASemashko

The issue was resolved by setting the settings in php and setting the necessary rights.

R
romy4, 2015-12-27
@romy4

copy the necessary odbc variables
/home/odbcinst.ini from the current user - very strange paths

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question