I am trying to convert the Mysqli code to use PDO
Mysqli code looks like the following (which works great)
$rs = "SELECT * FROM team";
$result = mysqli_query($con,$rs);
$data = mysqli_num_rows($result);
$responses = array();
if($data != 0) {
while($results = mysqli_fetch_assoc($result))
{
echo "<tr><td>".$results['code'] ."</td>";
echo "<td>".$results['username'] ."</td>";
}
My PDO code I tried
$stmt = $con->prepare("select * from team");
$stmt->execute();
if($stmt->rowCount() > 0)
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
How should I write a while loop here
on w3schools website, the information given to retrieve the records using PDO is as below, which did not say what is V and doesn't say how do I retrieve the fields code
and username
from the table.
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}