FVxSF Posted May 12, 2008 Share Posted May 12, 2008 I've been working on a basic database class and so far every thing works just fine except for fetching an array. When I try to fetch an array I get caught in an infinite loop. But once I take the code out of the class, it works as expected. Can some one help me? <?php class DB { var $ReportError; function Connect() { $cnRes = mysql_connect(cSERVER, cUSER, cPASSWORD); if (!$cnRes) { $this->ReportError = mysql_error(); return false; } else { $cnSRes = mysql_select_db(cSELECTED); if (!$cnSRes) { $this->ReportError = mysql_error(); return false; } } return true; } function FetchArray($SQL) { $reRes = mysql_query($SQL); if (!$reRes) { return false; } return mysql_fetch_array($reRes); } } $DB = new DB; if (!$DB->Connect()) { die($DB->ReportError); } $SQL = "SELECT * FROM node_files LIMIT 0,1"; while( $Row = $DB->FetchArray($SQL) ) { echo $Row[file_name] ." - ". $Row[file_location] ."<br>\n"; } I'm probably doing a noobish thing. Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/105291-solved-infinite-array-class-loop-problem/ Share on other sites More sharing options...
rarebit Posted May 12, 2008 Share Posted May 12, 2008 You don't need the 'fetcharray()' function, it just keeps making queries over and over.. $DB = new DB; if (!$DB->Connect()) { die($DB->ReportError); } $SQL = "SELECT * FROM node_files LIMIT 0,1"; $reRes = mysql_query($SQL); if ($reRes) { while( $Row = mysql_fetch_array($reRes) ) { echo $Row[file_name] ." - ". $Row[file_location] ."<br>\n"; } } Link to comment https://forums.phpfreaks.com/topic/105291-solved-infinite-array-class-loop-problem/#findComment-539156 Share on other sites More sharing options...
FVxSF Posted May 12, 2008 Author Share Posted May 12, 2008 Ok. I'll move the mysql_fetch_array out of the class. I'll be using this class on my site and my buddies site. Saves time. <?php $SQL = "SELECT * FROM node_files LIMIT 0,1"; $reRes = $DB->RunQuery($SQL); while( $Row = mysql_fetch_array($reRes) ) { echo $Row[file_name] ." - ". $Row[file_location] ."<br>\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/105291-solved-infinite-array-class-loop-problem/#findComment-539164 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.