php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17719 Code Garbage in Longtext results
Submitted: 2002-06-11 20:00 UTC Modified: 2002-11-21 17:08 UTC
Votes:5
Avg. Score:5.0 ± 0.0
Reproduced:5 of 5 (100.0%)
Same Version:1 (20.0%)
Same OS:2 (40.0%)
From: p-h-p-2 at g-u-s-t-l dot at Assigned:
Status: No Feedback Package: ODBC related
PHP Version: 4.2.2 OS: W98,W2K,XP
Private report: No CVE-ID: None
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
9 + 8 = ?
Subscribe to this entry?

 
 [2002-06-11 20:00 UTC] p-h-p-2 at g-u-s-t-l dot at
I'm connecting to a MSSQL database via ODBC (due to the PHP-MSSQL umlaut problem), with new version 4.2.1 I am getting code garbage from php in long text results, this doesnt happen with 4version .1.1,

Gustav Graf

here is part of the garbage, maybe it helps:
tschechischen Diskurs begegnen. 
	Diese Best?ndigkeit und vor allem der h<---garbage start --> 4T?de? Pd?T??4 ?"?#? T(??&??G? ?h?,?LLE, ART_ABSTRACT, ART_STATION, ART_PDF,
        ART_OK FROM Artikel
        WHERE ART_ID = 239;tf???4??g??,g?0.390s: SELECT ART_TITEL, ART_AUTOR, ART_QUELLE, ART_ABSTRACT, ART_STATION, ART_PDF,
        ART_OK FROM Artikel
        WHERE ART_ID = 239;?f?? 4?.??<PRE>0.313s: CONNECT TO dzmsq OPEN dzmsq
0.382s: SELECT TOP 1 * FROM Artikel
0.390s: SELECT ART_TITEL, ART_AUTOR, ART_QUELLE, ART_ABSTRACT, ART_STATION, ART_PDF,
        ART_OK FROM Artikel
        WHERE ART_ID = 239;
 <?y <??f??h?f?Dl??3?N<PRE>0.313s: CONNECT TO dzmsq OPEN dzmsq
0.382s: SELECT TOP 1 * FROM Artikel?h?& ?3?Pj?<j????< ,j??j?#?<?lj??&?6?7?igh< Pj??j?(?j??$??$??6?x???c	< ?j?k?(pG?pG??????c	$ ?j?(k?(?< k?dk?(??њ
Dk??$?p*??*?high/?< (k? k?'???x|?k??????res\ dk?\??@?k?$ ?/? l????ywG??A" + $ ?k?Dl??(?<  l??3?(?=
 `l? &?p*?stop<  +?L?#??l?)?Tl?this$ ?n??l??T+?< ?l?D+?(??n?Q?
?l??5??"?this$ D+?@m?tm?	$ m?dm?	?Pm?nvarchar$ @m??m?
 ??ART_AUTORD dm??m?0??])H
?m?t)??m??? n?ART_SUBTITELD ?m?n?-?:?
?m?7? n??m??4??4?ART_AUTORmeD ?m?P?.?M7?,n?0?`??m??m??ART_QUELLEecww< ???a?(T(?T(??G??f??c	< 8o??n?(?????0??"??c	$ ?n??l?	?nvarchar?Sww$ ???o?dn?$ ?n?8o?	?nvarchar< o??n?#?To????this? >?Ʃ <-- garbage end -->Transit - 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-12 01:33 UTC] mfischer@php.net
Can you test this on W2k ? We've a bad rate at fixing w98 because it mostly turns out it's a bug in the OS.
 [2002-06-12 19:31 UTC] php at remove dot gustl dot net
Yes, problem persists with W2K and V4.2.1,

Gustav Graf
 [2002-06-14 13:27 UTC] kalowsky@php.net
can you please provide a sample script and schema to reproduce this problem?
 [2002-06-14 16:40 UTC] php at remove dot gustl dot net
here is my sample script:
<?PHP
    echo "big db test<br>";
    $max       = 10000;

    $db   = odbc_connect ($DB, $DBAppUser, $DBAppPass) or die ("no connect");
    $res  = odbc_exec ($db, "SET TEXTSIZE ".(2 * $max));
    $res  = odbc_exec ($db, "DROP TABLE Test");
    $res  = odbc_exec (
      $db,
      "CREATE TABLE test (
        TEST_ID int NOT NULL IDENTITY PRIMARY KEY,
        TEST_TEXT ntext NULL
      )");
    $text = "";
    for ($i = 0; strlen ($text) < $max; $i++)
      $text .= "$i\n";
    echo strlen ($text)." chars written<br>";
    $res = odbc_exec ($db, "INSERT INTO Test (TEST_TEXT) VALUES ('$text')");
    $res = odbc_exec ($db, "SELECT TEST_TEXT FROM Test WHERE TEST_ID = 1");
    odbc_longreadlen ($res, $max);
    $text = odbc_result ($res, "TEST_TEXT");
    echo strlen ($text)." chars received<br>";
    echo "<listing>".htmlentities($text)."</listing>";
    echo "done";
?>

with PHP 4.2.1 I get following response:
big db test
10000 chars written
15904 chars received
0
1
2
<.. all ok until >
1039
1040
1? ?<66
1767
1768
<.. all ok until >
2220
2221
')' @?> tz0?$?t???< ??l?#?|??x?B$ 0? ?
TEST_TEXT<> (?!>0
1
2
<.. not ok double values starting again from 1>
1039
1040
1? ?<

done

with PHP 4.1.1 I get:
big db test
10000 chars written
10000 chars received
0
1
2
<.. all values ok>
2220
2221

done

maybe I make a mistake when switching PHP versions: I just rename the directories and copy the corrsponding php4ts.dll into the windows system dir (c:\windows\system on win98; c:\winnt\system32 on w2k)? Just the zlib extension is loaded.
 [2002-06-24 09:29 UTC] kalowsky@php.net
Seeing your code my initial reaction is... NTEXT is not a valid ODBC type.  At least not in ODBC v2 which what PHP is using (it is valid in OBDC 3.5/3.7).  

Any chance you can use VARCHAR, which is a valid ODBC type?
 [2002-06-24 17:10 UTC] php at remove dot gustl dot net
No, I cannot change the table definitions, because they are parts of an existing application. I was very happy to find out the "SET TEXTSIZE" trick, do get access to the NTEXT columns, without that PHP was and is still crashing. 
But something must have changed from PHP version 4.1.1 to 4.2.1, that this is not working any more.

Reminds me a littlebit on that error I had with an WinXP Apache 1.3.19 installation, where I got simmilar code garbage in html results, I found a patch for apache to fix that, maybe that helps

Gustav Graf
 [2002-06-24 17:16 UTC] kalowsky@php.net
Unfortunately I cannot test this.  My local database dies upon trying to create a table with type NTEXT via ODBC.
 [2002-06-24 17:31 UTC] php at remove dot gustl dot net
do you use a mssql database? then you can create the table with the mssql enterprise manager, or a can open you a mssql test access on my server, 

Gustav Graf
 [2002-06-24 17:43 UTC] kalowsky@php.net
Please realize that while database A may support functionality MNOP, ODBC functionality is NOT assured.  

To answer the question, no I do not use an MS database.  My testing comes from using iODBC and unixODBC ODBC drivers, and Virtuoso and PostgreSQL-ODBC for functionality.  
 [2002-06-24 18:54 UTC] paul at distributed dot net
4.1.2 seems to provide the correct output from the page.
current cvs version seems to corrupt output.

dank, i could probably give you remote access or get a debugger loaded on it tomorrow.

Paul
 [2002-08-13 19:55 UTC] kalowsky@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2002-08-16 07:10 UTC] php at remove dot gustl dot net
what kind of feedback do you need?
 [2002-08-16 09:54 UTC] kalowsky@php.net
First of type NTEXT is not a valid ODBC v2 type.  It is valid in later versions of ODBC but we don't support them yet.   I'm waiting for some manuals to show before I finish my work on it. 

Second one thing to try that a few people have reported success with it running a sql query with this information in it: "SET TEXTSIZE <some really large number here>"  See if that works for you.  

Also there have been a few bug fixes in the latest CVS.  Feel free to try it as well, although I didn't touch any of the longreadlen code.
 [2002-09-21 01:52 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2002-10-01 21:29 UTC] p-h-p-2 at g-u-s-t-l dot at
Sorry about late nite feedback,

but I found something new in PHP V4.2.2:
when you set odbc_longreadlen (0, $max) - with no resource id - it works fine, when you set it after the query with resulting resource id - odbc_longreadlen ($res, $max) - it failes and returns 4096 bytes less (what in my opinion is the default readlen from php.ini). see provided example:

<?PHP
    echo "big db test<br>";
    $DB        = '';
    $DBAppUser = '';
    $DBAppPass = '';
    $max       = 5000;

    $db   = odbc_connect ($DB, $DBAppUser, $DBAppPass) or die ("no connect");

##  create db

    $res  = odbc_exec ($db, "SET TEXTSIZE ".($max * 2));
    $res  = odbc_exec ($db, "DROP TABLE Test");
    $res  = odbc_exec (
      $db,
      "CREATE TABLE test (
        TEST_ID int NOT NULL IDENTITY PRIMARY KEY,
        TEST_TEXT ntext NULL
      )");
      
##  fill text

    $text = "";
    for ($i = 0; strlen ($text) <= $max; $i++)
      $text .= "$i\n";
    $text = substr ($text, 0, $max);
    echo strlen ($text)." chars written,  last $i<br>";
    $res = odbc_exec ($db, "INSERT INTO Test (TEST_TEXT) VALUES ('$text')");
    
##  read and set odbc_readlen with query result

    $res = odbc_exec ($db, "SELECT TEST_TEXT FROM Test WHERE TEST_ID = 1");
#    odbc_binmode ($res, 0);
    odbc_longreadlen ($res, $max);

    $text = odbc_result ($res, "TEST_TEXT");
    echo strlen ($text)." chars received (", strlen ($text) + 4096 , " when 4096 added)<br>";
    echo $text, "<br>";


##  read and set odbc_readlen with without result

#    odbc_binmode (0, 0);
    odbc_longreadlen (0, $max);

    $res = odbc_exec ($db, "SELECT TEST_TEXT, TEST_ID FROM Test WHERE TEST_ID = 1");
    $text = odbc_result ($res, "TEST_TEXT");
    echo strlen ($text)." chars received (", strlen ($text) + $max , " when $max added)<br>";
    echo $text, "<br>";

    echo "done";

?>

hope this gives you a clue

gustav graf

remove -'s from email to reply directly
 [2002-10-02 06:13 UTC] sniper@php.net
Please try using this CVS snapshot:

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


 [2002-10-02 15:35 UTC] p-h-p-2 at g-u-s-t-l dot at
same with win32-latest, 

maybe odbc returns a strange odbc-type, so this is handled as a non-long type and binded to the result in odbc_exec and then not read completely afterwards in odbc_result () with some kind of missinterpresting and missallocating some memory? This would explain the different results when calling odbc_longreadlen () without or with the query result.
 [2002-11-10 18:41 UTC] iliaa@php.net
Please try using this CVS snapshot:

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


 [2002-11-21 17:08 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2003-06-30 06:40 UTC] titangem at hotmail dot com
I believe that I am experiencing this same bug with PHP 4.3.0 on WinXP Pro. I get garbage when retrieving some (it only seems to occur with large records) ntext fields from a MSSQL Server 2K DB through ODBC. I'm not using the MSSQL library because I need Unicode support which will never be implemented (according to this: http://www.phpbuilder.com/mail/php-windows/2003031/0193.php).

I need to convert the database to mySQL, which is not possible with all the garbage I'm getting from some fields. I have to import hundreds of thousands of records, and I need to be sure that the data hasn't been damaged.

Do you have any further suggestions not mentioned in this thread?

Thanks,
Jozef
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 05:01:26 2024 UTC