php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39802 PHP segfaults with odbc_connect()
Submitted: 2006-12-11 22:26 UTC Modified: 2006-12-11 23:39 UTC
From: webmaster at guestwho dot com Assigned:
Status: Closed Package: ODBC related
PHP Version: 5.2.0 OS: FreeBSD 6.1-RELEASE
Private report: No CVE-ID: None
 [2006-12-11 22:26 UTC] webmaster at guestwho dot com
Description:
------------
I have been trying to connect a microsoft access database using PHP, mdbtools and unixODBC, but any attempt at calling odbc_connect() results in an immediate segfault.

This behaviour occurs in both the shared apache module and the standalone cgi version. Only the latter dumps core though.

PHP is configured as follows:

./configure  --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql \
             --with-zlib --with-pdo-mysql=/usr/local/mysql --enable-mbstring \
             --with-curl=/usr/local --enable-debug --with-openssl=/usr/local/ssl \
             --with-gd --with-custom-odbc=/usr/local

Here are the unixODBC configs:

odbcinst.ini
-------------
[MDBToolsODBC]
Description             = MDB Tools ODBC drivers
Driver          = /usr/local/lib/libmdbodbc.0
Setup           =
FileUsage               = 1
CPTimeout               =
CPReuse         =
DisableGetFunctions             = 0
UsageCount              = 1
--------------


odbc.ini
--------------
[Water]
Description = Water Module
Driver = MDBToolsODBC
Trace               = Yes
TraceFile           = /var/log/sql.log
Database = /home/skeleton-man/public_html/water/water.mdb
Servername = localhost
UserName =
Password =
---------------

Reproduce code:
---------------
<?
$myDB = odbc_connect('Water','','');
$query = "SELECT RLCode FROM Account";
$result = odbc_exec($myDB, $query);

while (odbc_fetch_row($result)){
 print odbc_result($result,'RLCode')."<br>";
}
?>

Expected result:
----------------
It should print a list of account numbers from the RLCode column in the database.

Actual result:
--------------
PHP segfaults immediately with no output.

Backtrace:

#0  0x082ef680 in zend_hash_find (ht=0x8829668,
    arKey=0x884137c "unixODBC_Water___2", nKeyLength=19, pData=0x10000)
    at /usr/local/src/php-5.2.0/Zend/zend_hash.c:849
#1  0x081a26ac in odbc_do_connect (ht=3, return_value=0x8841364,
    return_value_ptr=0x0, this_ptr=0x0, return_value_used=1, persistent=0)
    at /usr/local/src/php-5.2.0/ext/odbc/php_odbc.c:2341
#2  0x081a1c13 in zif_odbc_connect (ht=3, return_value=0x8841364,
    return_value_ptr=0x0, this_ptr=0x0, return_value_used=1)
    at /usr/local/src/php-5.2.0/ext/odbc/php_odbc.c:2053
#3  0x083008a6 in zend_do_fcall_common_helper_SPEC (execute_data=0xbfbfd510)
    at zend_vm_execute.h:200
#4  0x0830002d in execute (op_array=0x8840a84) at zend_vm_execute.h:92
#5  0x082e87c3 in zend_execute_scripts (type=8, retval=0x0, file_count=3)
    at /usr/local/src/php-5.2.0/Zend/zend.c:1097
#6  0x082b1ee5 in php_execute_script (primary_file=0xbfbfec00)
    at /usr/local/src/php-5.2.0/main/main.c:1758
#7  0x083615ba in main (argc=2, argv=0xbfbfeca8)
    at /usr/local/src/php-5.2.0/sapi/cgi/cgi_main.c:1625


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-11 22:29 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [2006-12-11 22:48 UTC] webmaster at guestwho dot com
Attempting building the latest CVS, which fails as follows:

/usr/local/src/php5.2-200612112130/ext/odbc/php_odbc.c: In function `zif_odbc_tableprivileges':
/usr/local/src/php5.2-200612112130/ext/odbc/php_odbc.c:3620: error: syntax error before "rc"
/usr/local/src/php5.2-200612112130/ext/odbc/php_odbc.c:3642: error: `rc' undeclared (first use in this function)
/usr/local/src/php5.2-200612112130/ext/odbc/php_odbc.c:3642: error: structure has no member named `hdbc'
/usr/local/src/php5.2-200612112130/ext/odbc/php_odbc.c:3642: error: structure has no member named `stmt'
/usr/local/src/php5.2-200612112130/ext/odbc/php_odbc.c:3643: error: `SQL_INVALID_HANDLE' undeclared (first use in this function)
/usr/local/src/php5.2-200612112130/ext/odbc/php_odbc.c:3649: error: `SQL_ERROR' undeclared (first use in this function)
/usr/local/src/php5.2-200612112130/ext/odbc/php_odbc.c:3650: error: `SQL_NULL_HSTMT' undeclared (first use in this function)
/usr/local/src/php5.2-200612112130/ext/odbc/php_odbc.c:3655: warning: implicit declaration of function `SQLTablePrivileges'
/usr/local/src/php5.2-200612112130/ext/odbc/php_odbc.c:3655: error: structure has no member named `stmt'
/usr/local/src/php5.2-200612112130/ext/odbc/php_odbc.c:3656: error: `SWORD' undeclared (first use in this function)
/usr/local/src/php5.2-200612112130/ext/odbc/php_odbc.c:3656: error: `SQL_NTS' undeclared (first use in this function)
/usr/local/src/php5.2-200612112130/ext/odbc/php_odbc.c:3666: error: structure has no member named `numparams'
/usr/local/src/php5.2-200612112130/ext/odbc/php_odbc.c:3667: error: structure has no member named `stmt'
/usr/local/src/php5.2-200612112130/ext/odbc/php_odbc.c:3667: error: structure has no member named `numcols'
/usr/local/src/php5.2-200612112130/ext/odbc/php_odbc.c:3669: error: structure has no member named `numcols'
*** Error code 1
 [2006-12-11 22:59 UTC] tony2001@php.net
Please make sure the sources are not broken in some weird way. The "rc" variable is of type "RETCODE" which is used innumerable times before that line.
Or maybe the error happens somewhere before that point, but you've posted only the last lines of the output.
 [2006-12-11 23:16 UTC] webmaster at guestwho dot com
I just posted the latest few lines..  the full ouput is over 700 lines, so you may view it at: http://www.guestwho.com/php/makelog
 [2006-12-11 23:19 UTC] webmaster at guestwho dot com
This looks like the source of my troubles, tho I'm not sure how to rectify it:

In file included from /usr/local/src/php5.2-200612112130/ext/odbc/php_odbc.c:37:
/usr/local/src/php5.2-200612112130/ext/odbc/php_odbc_includes.h:184:18: odbc.h: No such file or directory
 [2006-12-11 23:21 UTC] tony2001@php.net
>odbc.h: No such file or directory
Missing ODBC includes?
 [2006-12-11 23:39 UTC] webmaster at guestwho dot com
You are right, I solved my issue by creating /usr/local/include/odbc.h with the following:

#include <sql.h>
#include <sqlext.h>
#include <odbcinst.h>

This solved both my original problem and the problem with building the latest cvs.

Note to others.. read the following instructions: http://www.unixodbc.org/doc/php3.html

Thanks tony2001. Bug Closed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 08 18:01:34 2024 UTC