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
isql -v remote
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 /etc/apache2/envvars
as well as in the vhost using SetEnv
.
My PHP script is as follows:
<?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);
The script runs fine from the command line:
sudo -u www-data /usr/bin/php /var/www/odbc.php
and outputs as expected.
However, accessing http://example.org/odbc.php results in a blank page and no data is being sent from Apache (checked with wget and Chrome). Using tcpdump
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.
Why is Apache not returning any data?
EDIT:
using gdb
and stepping through the apache webserver process that is handling the request, I get this error:
Program received signal SIGSEGV, Segmentation fault.
0x00007ff48c68ea2f in ErrStmtWithState () from /usr/local/psql/lib64/libodbcci.so
Looks like a bug, no?
When I ran your code, I got a message saying that
odbc_result_all
expects parameter 1 to be a resource.When I changed it to the following, it worked:
This makes sense because
odbc_excute
is declared as:and
odbc_result_all
is declared as:in the PHP docs.