|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-05-26 18:16 UTC] erudd at netfor dot com
Description:
------------
Using the mssql extension from PHP 4.3.11 on an x86_64 system. (core PHP is latest FC3 RPMS, php-mssql is custom compiled RPM using freetds 0.63). Everything works fine except for calling the mssql_next_result function (via PEAR::DB 1.7.6) apache and the command line client will segfault. This works fine on a MDK 10.1 32bit system w/ PHP 4.3.8.
I havn't yet tried on a FC3 x86 system
Also the freetds commandline 'tsql" command runs the query without any issues and returns all the result fields.
Reproduce code:
---------------
require_once("DB.php");
$db =& DB::connect("mssql://user:pass@server/Database");
$sql = <<<EOSQL
DECLARE Search CURSOR LOCAL SCROLL READ_ONLY FOR
SELECT * FROM MyTable
DECLARE @limit INT, @offset INT
SET @limit = 20
SET @offset = 5
OPEN Search
FETCH ABSOLUTE @offset FROM Search
WHILE @@FETCH_STATUS =0 AND @limit > 1
BEGIN
FETCH NEXT FROM Search
SET @limit = @limit -1
END
CLOSE Search
DEALLOCATE Search
EOSQL;
$res =& $db->query($sql);
$row =& $res->fetchRow(DB_FETCHMODE_ASSOC);
do {
$return[] =& $row;
$row =& $res->fetchRow(DB_FETCHMODE_ASSOC);
if (is_null($row)) {
if ($res->nextResult()) {
$row =& $res->fetchRow(DB_FETCHMODE_ASSOC);
}
}
} while ($row);
Expected result:
----------------
Not to segfault and return 20 records from the table starting at record 5
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 23:00:01 2025 UTC |
Backtrace of the crash. #0 dblastrow (dbproc=0x8c9530) at dblib.c:5909 #1 0x0000002a9a7f54bf in zif_mssql_next_result (ht=9213232, return_value=0x7bde58, this_ptr=0x9034a0, return_value_used=9454256) at /home/erudd/RPMBUILD/BUILD/php-4.3.11/ext/mssql/php_mssql.c:1865 #2 0x000000000051c405 in execute (op_array=0x8004b8) at /usr/src/debug/php-4.3.11/Zend/zend_execute.c:1654 #3 0x000000000051891b in execute (op_array=0x7f3128) at /usr/src/debug/php-4.3.11/Zend/zend_execute.c:1698 #4 0x000000000051891b in execute (op_array=0x7af1b8) at /usr/src/debug/php-4.3.11/Zend/zend_execute.c:1698 #5 0x000000000050869d in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/src/debug/php-4.3.11/Zend/zend.c:926 #6 0x00000000004dc14a in php_execute_script (primary_file=0x7fbffff550) at /usr/src/debug/php-4.3.11/main/main.c:1745 #7 0x000000000052384a in main (argc=3, argv=0x7fbffff688) at /usr/src/debug/php-4.3.11/sapi/cgi/cgi_main.c:1601Problem here is that in mssql_next_result PHP do not ignore recordset without columns in mssql_query /* Skip results not returning any columns */ while ((num_fields = dbnumcols(mssql_ptr->link)) <= 0 && retvalue == SUCCEED) { retvalue = dbresults(mssql_ptr->link); } in mssql_execute /* Skip results not returning any columns */ while ((num_fields = dbnumcols(mssql_ptr->link)) <= 0 && retval_results == SUCCEED) { retval_results = dbresults(mssql_ptr->link); } but there is no such loop in mssql_next_result freddy77Patch based on PHP_5_0 head branch applies to php 5.0.4 and php 4.3.10. tested and works with every I could throw at it (32 bit and 64 bit) Index: php_mssql.c =================================================================== RCS file: /repository/php-src/ext/mssql/php_mssql.c,v retrieving revision 1.137.2.9 diff -u -r1.137.2.9 php_mssql.c --- php_mssql.c 12 Apr 2005 17:46:06 -0000 1.137.2.9 +++ php_mssql.c 14 Oct 2005 23:02:42 -0000 @@ -1829,10 +1829,15 @@ WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE(result, mssql_result *, mssql_result_index, -1, "MS SQL-result", le_result); mssql_ptr = result->mssql_ptr; retvalue = dbresults(mssql_ptr->link); + + while (dbnumcols(mssql_ptr->link) <= 0 && retvalue == SUCCEED) { + retvalue = dbresults(mssql_ptr->link); + } + if (retvalue == FAIL) { RETURN_FALSE; }