Previously am using mysql to loop on users data getting the table row by rws[0], now that i change to pdo i still need to use this rws[0] get each row instead of using the row name like this $id = $rws->id; in pdo how can i make this work in pdo?
OLD MYSQL
<?php
include('co.php');
$sql="SELECT * FROM users";
$result= mysql_query($sql) or die(mysql_error());
while($rws = mysql_fetch_array($result)){
$id = $rws[0];
$name = $rws[1];
$email = $rws[2];
}
?>
NEW PDO
<?php
$sql = new DBController();
$sql->prepare("SELECT * FROM users");
$sql->execute();
$result = $sql->getAll();
$sql->free();
if(!is_null($result)){
foreach($result as $i => $rws){
$id = $rws->id; // just want it to be this >> $id = $rws[0];
$name = $rws->name; // I tried this $name = $rws->[0];
$email = $rws->email;
}
}
?>
