Jsama Posted September 17, 2009 Share Posted September 17, 2009 Hello Hi, I have a question about connecting PHP to Access. I read the tutorial in w3schools and do the exact coding as it listed there. http://www.w3schools.com/PHP/php_db_odbc.asp However, when I run odbc_fetch_row and pretty often the page just keeps loading and loading until 30s timeout, seems that odbc_fetch_row does not return false even though when it reaches the last record, may I ask if there is anyway to correct this? and funny thing is, this odbc_fetch_row problem only affect one table in a database but not the others in the same database.... not too sure why. any ideas would be highly appreciated. Thanks very much. Link to comment https://forums.phpfreaks.com/topic/174546-infinitely-loop-in-odbc_fetch_row/ Share on other sites More sharing options...
trq Posted September 17, 2009 Share Posted September 17, 2009 Post your code. Link to comment https://forums.phpfreaks.com/topic/174546-infinitely-loop-in-odbc_fetch_row/#findComment-919929 Share on other sites More sharing options...
Jsama Posted September 17, 2009 Author Share Posted September 17, 2009 sure, my bad. Here it is. and Thanks a lot. the page just keep loading, sometime it just does not display anything on the web or sometime it displays some data while loading.... Thanks. $conn=odbc_connect('timelog','',''); if (!$conn) {exit("Connection Failed: " . $conn);} $sql = "select * from Workbook"; $rs=odbc_exec($conn,$sql); if (!$rs) {exit("Error in SQL");} echo "<table><tr>"; echo "<th>Subject</th>"; echo "<th>Item</th>"; echo "<th>Total</th></tr>"; while (odbc_fetch_row($rs)) { $wsSubject=odbc_result($rs,"Subject"); $wsItem=odbc_result($rs,"Workbook"); $total=odbc_result($rs,"TotalNum"); echo "<tr><td>$wsSubject</td>"; echo "<td>$wsItem</td>"; echo "<td>$total</td></tr>"; } odbc_close($conn); echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/174546-infinitely-loop-in-odbc_fetch_row/#findComment-919934 Share on other sites More sharing options...
trq Posted September 17, 2009 Share Posted September 17, 2009 Nothing technically wrong with your code. How many records is your query returning? Access isn't exactly a top notch db. Link to comment https://forums.phpfreaks.com/topic/174546-infinitely-loop-in-odbc_fetch_row/#findComment-920036 Share on other sites More sharing options...
Jsama Posted September 17, 2009 Author Share Posted September 17, 2009 yeah, that is the weird thing. I am retrieving around 1800 records only. But when i try to retrieve more than 10000 records from another table in the same database, it runs without any problems... that is really weird. and yes, i agree access shouldn't be used, but sadly my users is more comfortable with ms product.... :'( Link to comment https://forums.phpfreaks.com/topic/174546-infinitely-loop-in-odbc_fetch_row/#findComment-920122 Share on other sites More sharing options...
PFMaBiSmAd Posted September 17, 2009 Share Posted September 17, 2009 The different symptoms for different tables are probably due to the amount of data being retrieved or the optimization of the tables and how long it takes to query/retrieve the data. Add the following two lines of code immediately after your first opening <?php tag to see exactly what if any php detected errors are occurring - ini_set("display_errors", "1"); error_reporting(E_ALL); And why on earth would you need to retrieve 1800 or 10000 records from any table on one web page? You only retrieve the data you want in the order that you want it. Link to comment https://forums.phpfreaks.com/topic/174546-infinitely-loop-in-odbc_fetch_row/#findComment-920127 Share on other sites More sharing options...
Jsama Posted September 17, 2009 Author Share Posted September 17, 2009 Hi PFMaBiSmAd Thanks for your reply. I added those 2 lines of code but there is no error... and yeah, normally i won't retrieve more than a thousand records, but it is still same case if i retrieve only a couple of hundreds of records... :'( Link to comment https://forums.phpfreaks.com/topic/174546-infinitely-loop-in-odbc_fetch_row/#findComment-920180 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.