Bug #73448 [Com]: odbc_errormsg returns trash, always 513 bytes

From: Date: Mon, 07 Nov 2016 20:57:26 +0000
Subject: Bug #73448 [Com]: odbc_errormsg returns trash, always 513 bytes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205230@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73448&edit=1

 ID:                 73448
 Comment by:         honza dot hink at gmail dot com
 Reported by:        honza dot hink at gmail dot com
 Summary:            odbc_errormsg returns trash, always 513 bytes
 Status:             Closed
 Type:               Bug
 Package:            ODBC related
 Operating System:   Windows 7, 8.1, Server 2012 R2
 PHP Version:        7.0.12
 Assigned To:        ab
 Block user comment: N
 Private report:     N

 New Comment:

I have tested it with version 7.1.0-dev and I can confirm the bug is gone. Thanks.


Previous Comments:
------------------------------------------------------------------------
[2016-11-07 20:01:17] ab@php.net

Fixed in 7.0+, please check latest http://windows.php.net/snapshots/ . Also note, that the
error is not cleared after the successful query. That's the current behavior. From the doc:

This function returns meaningful value only if last odbc query failed (i.e. odbc_exec() returned
FALSE).

Maybe it's something worth to change, but not sure. Please use another ticket, if you think
it's worth pursuing.

Thanks.

------------------------------------------------------------------------
[2016-11-07 19:23:46] ab@php.net

Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3558e70e58f0980cb86e5343947f4876017ef3e3
Log: Fixed bug #73448 odbc_errormsg returns trash, always 513 bytes

------------------------------------------------------------------------
[2016-11-02 22:53:37] honza dot hink at gmail dot com

Description:
------------
If odbc_exec returns false then odbc_errormsg returns always 513 bytes in my examples. The correct
error message is at the beginning, then some null bytes follows and the rest is binary trash.

If next odbc_exec is OK then odbc_errormsg returns similar content as before, the trash may be
different. It doesn't return empty string as written in documentation.

The example (19 lines) can be used as simple page (like index.php).
It contains 4 SQL commands and displays error text in raw and hexadecimal form.

Adjust parameters in odbc_connect.

The bug appears in ODBC with MS SQL 2008, 2012, probably all versions, Apache/2.4.17 (Win32) or IIS
7, FCGI mode, mod_fcgid/2.3.9.
First noticed several months ago, problem probably started with 7.0.0.


Test script:
---------------
<?php
	$con=odbc_connect("MSSQLLocal","sa","your-pwd");
	$sqlCommandList=array("/* empty batch is without error */","/* non existent
procedure xy */ execute xy",
		"/* empty batch, error message is not empty */","/* valid select with result */
select * from sys.sysobjects");
	foreach($sqlCommandList as $exampleNumber=>$sql){
		$r = @odbc_exec($con,$sql);
		$exampleNumber++;
		if($r)
			{$numfields="Result = $r, field count = ".odbc_num_fields($r); odbc_free_result($r);}
		else
			{$numfields="Invalid result";}
		$e=odbc_errormsg($con);
		$hex=bin2hex($e);
		print "<hr style=height:5px; color=red><br><div
style=font-width:bold>Example $exampleNumber SQL =  $sql</div>
		<div>$numfields, error text(length=".strlen($e)."): </div>
		<div><pre>$e</pre></div><hr>
		<div style=font-weight:bold>Hexadecimal error content:</div>
		<div style=word-wrap:break-word;max-width:600px>$hex</div>";
	}



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=73448&edit=1


Thread (5 messages)

« previous php.bugs (#205230) next »