ID: 25585 Updated by: [EMAIL PROTECTED] Reported By: snick at getart dot ru Status: Open Bug Type: MSSQL related Operating System: Windows 2003 Server PHP Version: 4.3.3 New Comment:
The mssql_query function is supposed to stop at the first result. You should use mssql_next_result() to move the internal result pointer forward to the next result, if the query returns more than one result. That way you can process all the results in the query. I'll test the sample code to see if I get the same result and fix any errors that I might find. The driver should not crash on a RAISEERROR(). Previous Comments: ------------------------------------------------------------------------ [2003-11-30 21:14:16] msisolak at yahoo dot com I believe the problem here is in how mssql_query handles result sets that have multiple results returned, but none with rows (such as in this bug where there are multiple commands executed and multiple errors returned). In the php_mssql.c for PHP 4.3.4 the block at line 1145 reads: while ((num_fields = dbnumcols(mssql_ptr->link)) <= 0 && retvalue == SUCCEED) { retvalue = dbresults(mssql_ptr->link); } According to Microsoft (http://msdn.microsoft.com/library/en-us/dblibc/dbc_pdc04e_52sz.asp), however: "You must call dbresults until it returns NO_MORE_RESULTS, or any continued use of the DBPROCESS causes the DB-Library error 10038 'Results Pending'." As this code in php_mssql.c currently stands it stops looping the empty result sets too early becuase it's looking for SUCCEED instead of NO_MORE_RESULTS. Changing this code to: while ((num_fields = dbnumcols(mssql_ptr->link)) <= 0 && retvalue != NO_MORE_RESULTS) { retvalue = dbresults(mssql_ptr->link); } causes both SQL Server error messages generated by the sample query in the bug report to be correctly displayed and eliminates the fault. ------------------------------------------------------------------------ [2003-09-19 02:53:01] snick at getart dot ru Yes. Comments of mssql_get_last_message() changes situation, but not essentially: Under Apache and standalone will crash in any case. Under IIS crashes after four or five browser refreshes. ------------------------------------------------------------------------ [2003-09-19 00:57:38] [EMAIL PROTECTED] Does it crash without the mssql_get_last_message() line? ------------------------------------------------------------------------ [2003-09-18 07:39:06] snick at getart dot ru Description: ------------ When I try to execute T-SQL query with advanced instructions PHP was crash. Tested with: Apache v. 2.0.43 IIS v. 6.0 MSSQL v. 7.0 ntwdblib.dll v. 2000.80.194.0 Query must include: - BEGIN TRAN and COMMIT / ROLLBACK TRAN; - RAISEERROR() function call; - Error in query before RAISERROR (eg. failed INSERT with 'Can not insert NULL into bla-bla-bla' message (msg 515)) Reproduce code: --------------- // you must create database called 'myDB' and table // 'myTable' with columns myField1 INT NOT NULL, myField2 VARCHAR(50) NOT NULL /* ...db connection and selection */ $query = "BEGIN TRAN DECLARE @Flag BIT SET @Flag = 0 INSERT INTO myTable (myField2) VALUES ('akgfsjhdgf') IF @Flag = 0 BEGIN RAISERROR('Some error', 18, 10) ROLLBACK TRAN END ELSE COMMIT TRAN"; $result = mssql_query($query); echo "Result is ".($result ? "true" : "false")."<br/>"; echo "DB Error is ".mssql_get_last_message()."<br/>"; Expected result: ---------------- PHP must return usual errors (if exists) and specified output: Result is true DB Error is Changed database context to 'myDB' Actual result: -------------- If PHP running as Apache module: message box "Apache.exe - Application Error The instruction at '0x77f486f7' referenced memory at '0x00000000'. The memory could not be 'read'" If PHP running as standalone: message box "php.exe - Application Error The instruction at '0x77f486f7' referenced memory at '0x00000000'. The memory could not be 'read'" If PHP running as ISAPI module: IIS return in browser string "PHP has encountered an Access Violation at 77F47931" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=25585&edit=1