donglong1465 2014-11-19 22:06
浏览 44

ODBC连接通过命令行工作,而不是通过apache

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?

  • 写回答

2条回答 默认 最新

  • douzhong3887 2014-11-20 12:57
    关注

    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:

    <?php  
    $connect = odbc_connect("remote", "", "") or die("Could not connect.");  
    $query = "SELECT * FROM \"ITEMS\"";  
    $prepared = odbc_prepare($connect, $query);  
    if (!odbc_execute($prepared)) {
        die(odbc_errormsg()); 
    }
    if (odbc_result_all($prepared) < 1) {
        die(odbc_errormsg());
    }
    ?>
    

    This makes sense because odbc_excute is declared as:

    bool odbc_execute ( resource $result_id [, array $parameters_array ] )
    

    and odbc_result_all is declared as:

    int odbc_result_all ( resource $result_id [, string $format ] )
    

    in the PHP docs.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。