Options

Segmentation fault on odbc_fetch_array (PHP)

I have a PHP program that runs fine on CentOS 5.11 (Vertica 7.0.2/PHP 5.1.6-15/ODBC 2.2.11-10), but it's hitting a segmentation fault on CentOS 6.6 (Vertica 7.0.2/PHP 5.3.3-40/ODBC 2.2.14-14).

 

I've reproduced the problem in this simple PHP script:

 

 

$conn = odbc_connect("VerticaDSN", "user", "passwd");
$sql = "SELECT DATEDIFF('second', TO_TIMESTAMP('1970-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), MIN(Timestamp)) AS value FROM metrics_fact";
$result = odbc_exec($conn, $sql);
$row = odbc_fetch_array($result);

 

I've stripped out the debug lines for clarity, but the gist is that I'm getting a segmentation fault on the odbc_fetch() call. It is worth noting that the sql line given works when I try it in vsql, but it does return 0 rows with my current db contents.

 

On the other hand, it words fine on CentOS 5.11 under the same conditions.

 

I've tried using xdebug to look at this and I also tried running it with USE_ZEND_ALLOC=0, but I didn't get any more helpful info or different behavior.

 

Any suggestions? 

 

Thanks,

Jester

Comments

  • Options

    And, in another data point, this works fine when I tried a different query that does return some data.

     

    Jester

  • Options

    Well, I have managed to isolate the problem further and find a workaround. 

     

    There are three different possibilities in play when a query is made:

    1. The query has no data at all and odbc_fetch_array returns false
      1. This works as expected
    2. The query has one or more rows, each of which has data
      1. This also works just fine
    3. The query has a single row with no data
      1. This is the case when doing a query that involves a function call and null data, like my SQL statement above where there is no value for Min(Timestamp).
      2. This used to work but now gets a segmentation fault inside odbc_fetch_array()

    As a workaround, though, I do a simple query to see if there is a value there first. If it fails (case 1), then I don't do the real SQL query. If it succeeds, the real SQL query will work.

     

    Jester

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file