title: ODBC connection works through command line, not through apache
body: <p>I'm trying to connect to a Pervasive 11 DB on a remote system using PHP. The DSN is setup in /etc/odbc.ini. The psql (created by the Pervasive client installer) and www-data user can connect to the remote system using</p>
  
  <pre><code>isql -v remote  
  </code></pre>
  
  <p>Furthermore, the www-data user is added to the pvsw group and the needed environment variables PVSW_ROOT and LD_LIBRARY_PATH are set in <code>/etc/apache2/envvars</code> as well as in the vhost using <code>SetEnv</code>.</p>
  
  <p>My PHP script is as follows:</p>
  
  <pre><code>&lt;?php  
  $connect = odbc_connect("remote", "", "") or die("Could not connect");  
  $query = "SELECT * FROM \"ITEMS\"";  
  $prepared = odbc_prepare($connect, $query);  
  $result = odbc_execute($prepared);  
  odbc_result_all($prepared);  
  </code></pre>
  
  <p>The script runs fine from the command line:</p>
  
  <pre><code>sudo -u www-data /usr/bin/php /var/www/odbc.php
  </code></pre>
  
  <p>and outputs as expected.</p>
  
  <p>However, accessing <a href="http://example.org/odbc.php" rel="nofollow">http://example.org/odbc.php</a> results in a blank page and no data is being sent from Apache (checked with wget and Chrome). Using <code>tcpdump</code> shows the connection being made between the server and the Pervasive remote DB, both by invoking the script from the CLI as from Apache. The system is Debian 64 bit 7.7. 'LogLevel debug' is set in the vhost config, but no errors are logged.</p>
  
  <p>Why is Apache not returning any data?  </p>
  
  <p>EDIT:
  using <code>gdb</code> and stepping through the apache webserver process that is handling the request, I get this error:  </p>
  
  <pre><code>Program received signal SIGSEGV, Segmentation fault.  
  0x00007ff48c68ea2f in ErrStmtWithState () from /usr/local/psql/lib64/libodbcci.so  
  </code></pre>
  
  <p>Looks like a bug, no?</p>