I'm trying to move out all of my php legacy code to PDO Statments. All seems it works great, but I commonly use mysql_data_seek
function in cases like this, and I'm trying to find a way for PDO, but I honestly don't find anything related with this. This is what I actually do (without PDO)
$query = mysql_query("SELECT * sometable");
$array = mysql_fetch_assoc($query);
$name = $array['name']
// $name is returned well, but now I want to loop it, so I use mysql_data_seek to reset the query. I want just one row, not more.
mysql_data_seek($query, 0);
// now i can loop
while($arr = mysql_fetch_assoc($array)){
echo "name: " . $arr[$arr];
}
So now I'm trying to do something like this:
$query = $conn->query("SELECT * sometable");
$array = $query->fetch();
$name = $array['name'];
// It outputs just one row, that's what I really want to, so I want to loop it now.
foreach($query->fetchAll() as $loop){
echo $loop['name']
}
// This time I don't get anything...
Any suggestions? THANKS!