recordset gets messed up by EOF/ reading in it ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • John Doe
    New Member
    • Jun 2011
    • 20

    recordset gets messed up by EOF/ reading in it ?

    This is a copy of an old post in here, but (presumably because it is so old) I cannot post an answer to, so I am re-creating it....

    =============== =============== ==========


    Seems like a $rs-> EOF messes up the record set ?
    (using php 4.2.2 and MSSQL database)
    I try to read the ntext-field "body".



    THIS WORKS !!

    Code:
    $dbMail = new COM("ADODB.Connection");
    $dsn = "DRIVER={SQL Server}; SERVER={--------};UID={-----};PWD={-------};
    DATABASE={--------}";
    $dbMail->Open($dsn);
    
    $sql="select * from email INNER JOIN klassement ON email.id =
    klassement.mailid where email.id = '124' ORDER BY date_sent DESC";
    $rs=$dbMail->Execute($sql);
    
    $thebody=$rs->Fields["body"]->Value;
    echo $thebody;


    THIS PRINTS A ZERO ?????


    Code:
    $dbMail = new COM("ADODB.Connection");
    $dsn = "DRIVER={SQL Server}; SERVER={--------};UID={-----};PWD={-------};
    DATABASE={--------}";
    $dbMail->Open($dsn);
    
    $sql="select * from email INNER JOIN klassement ON email.id =
    klassement.mailid where email.id = '124' ORDER BY date_sent DESC";
    $rs=$dbMail->Execute($sql);
    while(!$rs->EOF)
    {
    $thebody=$rs->Fields["body"]->Value;
    echo $thebody;
    $rs->MoveNext();
    }
    $rs->Close();



    How is this possible???



    Also I see now that in the first case, if I try to echo twice the same , it
    doesn't print the second one:

    Code:
    echo $rs->Fields["body"]->Value; // prints the text
    echo $rs->Fields["body"]->Value; // prints nothing (even no zero)
    anyone ?
    Last edited by Niheel; Jun 15 '11, 10:39 AM. Reason: added code tags
  • John Doe
    New Member
    • Jun 2011
    • 20

    #2
    I have just been getting exactly the same problem while reading from an Access database. Wanted to post an answer in case someone finds it useful...

    My original code, which showed the same problem as above was:

    Code:
    $conn = new COM('ADODB.Connection') or exit('Cannot start ADO.');
    
    $conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$db");
    
    $rs = $conn->Execute($sql);
    
    $tf1 = $rs->Fields['sProductDescription']->Value;		// THIS LINE IS BLANKING THE FIELD DATA!!
    echo $tf1;							// THIS prints the data as expected
    $tf2 = $rs->Fields['sProductDescription']->Value;		// THIS LINE IS BLANKING THE FIELD DATA!!
    echo $tf2;							// THIS prints shows blank data
    =============== ==

    The solution for me was simply using a different connection string...

    Code:
    $conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");
    Last edited by Niheel; Jun 15 '11, 10:39 AM. Reason: added code tags

    Comment

    Working...