473,388 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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 !!

Expand|Select|Wrap|Line Numbers
  1. $dbMail = new COM("ADODB.Connection");
  2. $dsn = "DRIVER={SQL Server}; SERVER={--------};UID={-----};PWD={-------};
  3. DATABASE={--------}";
  4. $dbMail->Open($dsn);
  5.  
  6. $sql="select * from email INNER JOIN klassement ON email.id =
  7. klassement.mailid where email.id = '124' ORDER BY date_sent DESC";
  8. $rs=$dbMail->Execute($sql);
  9.  
  10. $thebody=$rs->Fields["body"]->Value;
  11. echo $thebody;


THIS PRINTS A ZERO ?????


Expand|Select|Wrap|Line Numbers
  1. $dbMail = new COM("ADODB.Connection");
  2. $dsn = "DRIVER={SQL Server}; SERVER={--------};UID={-----};PWD={-------};
  3. DATABASE={--------}";
  4. $dbMail->Open($dsn);
  5.  
  6. $sql="select * from email INNER JOIN klassement ON email.id =
  7. klassement.mailid where email.id = '124' ORDER BY date_sent DESC";
  8. $rs=$dbMail->Execute($sql);
  9. while(!$rs->EOF)
  10. {
  11. $thebody=$rs->Fields["body"]->Value;
  12. echo $thebody;
  13. $rs->MoveNext();
  14. }
  15. $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:

Expand|Select|Wrap|Line Numbers
  1. echo $rs->Fields["body"]->Value; // prints the text
  2. echo $rs->Fields["body"]->Value; // prints nothing (even no zero)
  3.  
anyone ?
Jun 15 '11 #1

✓ answered by John Doe

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:

Expand|Select|Wrap|Line Numbers
  1. $conn = new COM('ADODB.Connection') or exit('Cannot start ADO.');
  2.  
  3. $conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$db");
  4.  
  5. $rs = $conn->Execute($sql);
  6.  
  7. $tf1 = $rs->Fields['sProductDescription']->Value;        // THIS LINE IS BLANKING THE FIELD DATA!!
  8. echo $tf1;                            // THIS prints the data as expected
  9. $tf2 = $rs->Fields['sProductDescription']->Value;        // THIS LINE IS BLANKING THE FIELD DATA!!
  10. echo $tf2;                            // THIS prints shows blank data
  11.  
=================

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

Expand|Select|Wrap|Line Numbers
  1. $conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");

1 1006
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:

Expand|Select|Wrap|Line Numbers
  1. $conn = new COM('ADODB.Connection') or exit('Cannot start ADO.');
  2.  
  3. $conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$db");
  4.  
  5. $rs = $conn->Execute($sql);
  6.  
  7. $tf1 = $rs->Fields['sProductDescription']->Value;        // THIS LINE IS BLANKING THE FIELD DATA!!
  8. echo $tf1;                            // THIS prints the data as expected
  9. $tf2 = $rs->Fields['sProductDescription']->Value;        // THIS LINE IS BLANKING THE FIELD DATA!!
  10. echo $tf2;                            // THIS prints shows blank data
  11.  
=================

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

Expand|Select|Wrap|Line Numbers
  1. $conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");
Jun 15 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Dieter Beheydt | last post by:
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 !! $dbMail = new COM("ADODB.Connection"); $dsn =...
6
by: A_StClaire_ | last post by:
hi, wrote the following program to learn a bit about auto pointers. weird thing is, the char array 'name' with size 'max_size' displays a bunch of messed up symbols after the "John Smith" if...
3
by: Danny | last post by:
Hi again I am trying to import from an excel spreadsheet into access 2002, but the order that is in the spreadsheet is not preserved when I import. using DoCmd.TransferSpreadsheet in code. ...
9
by: jza | last post by:
I once had a program which would get a directory name in argv and append "/thumbmap.txt" after it. I couldn't get it to work because when defining some variables there would appear some garbage in...
2
by: Jim M | last post by:
I rarely deal with recordsets directly with code, since I usually use Access queries, so be patient with this question. I want to open a recordset with various default variables used by my program....
3
by: David C. Barber | last post by:
Using SQL Server 2000 and moving to a new computer. We did a full backup of the existing database to tape, brought up the new computer with a clean install using the same server name and IP...
23
by: PW | last post by:
Hi, I'd like to close a recordset and set the database to nothing if a recordset is open if an error has occured. Leaving a recordset open and a database open isn't a good idea, right? ...
2
by: Gurvinder Bains | last post by:
Ok here is my Problem. I am trying to place some data from my recordset onto the page , Just 4 in a row and next four should come in second line But the problem is my recordset gets empty befor...
2
by: DavidPr | last post by:
PHP Version 5.2.3 MySQL version - 5.0.45 magic_quotes_gpc - On I'm using the edit script below. When the form is displayed with the information to be edited - if there is a single quote in...
2
by: Quimbly | last post by:
Hi everyone, Please see this page in IE: http://shawnessy.ca/test.php The height of the top row (not the <TH> row) of the calendar gets messed up. The page looks fine under Firefox. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.