I am using a php while loop to read through results but it just loops continuously over the first record and never moves to the second record and never stops. My code:
class MySqlDatabase {
public function __construct() {
$this->Open_Connection();
}
//Vars for Function Open_Connection
private $_Connection;
//Function Open_Connection - Connects to DB
public function Open_Connection(){
$this->_Connection = mysqli_connect('localhost','xxx','xxx','xxx');
if(!$this->_Connection){
die("Connection Failed: ". mysqli_error($this->_Connection));
} else {
echo "Success";
}
}
//Vars for Function Query
public $Results_Row;
//Function Query - Runs Query and returns results
public function Query($Sql){
$Results = mysqli_query($this->_Connection, $Sql);
if(!$Results){
die("Query Failed: ". mysqli_error($Results). "<br/>".$Sql);
}
$this->Results_Row = mysqli_fetch_row($Results);
return $Results;
}
}
$Db = new MySqlDatabase;
$Db->Query("SELECT * FROM Users");
while ($R = $Db->Results_Row){
var_dump($R);
echo "<hr/>";
}
This is creating an infinite loop of the first record that never stops. There are only two records in my db so it should stop after looping through the two results. Again it just keep infinitely looping the first record and never moves to the second record and then stops.Please help, thank you.