php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73448 odbc_errormsg returns trash, always 513 bytes
Submitted: 2016-11-02 22:53 UTC Modified: 2016-11-08 12:30 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: honza dot hink at gmail dot com Assigned: ab (profile)
Status: Closed Package: ODBC related
PHP Version: 7.0.12 OS: Windows 7, 8.1, Server 2012 R2
Private report: No CVE-ID: None
 [2016-11-02 22:53 UTC] 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>";
	}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-11-07 19:23 UTC] 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-07 19:23 UTC] ab@php.net
-Status: Open +Status: Closed
 [2016-11-07 20:01 UTC] ab@php.net
-Assigned To: +Assigned To: ab
 [2016-11-07 20:01 UTC] 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 20:57 UTC] honza dot hink at gmail dot com
I have tested it with version 7.1.0-dev and I can confirm the bug is gone. Thanks.
 [2016-11-08 12:30 UTC] ab@php.net
Nice, thanks for checking!
 [2016-11-09 03:33 UTC] krakjoe@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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 11 18:01:27 2024 UTC