Hi
The following function should read data backwards but it is reading it forward. What could be the problem? I found this function at http://www.php.net/manual/en/pdostatement.fetch.php.
Any helps is much appreciated.
function readDataBackwards($dbh) {
$sql = 'SELECT cust_id, email, password FROM login ORDER BY cust_id';
try {
$stmt = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_LAST);
do {
$data = $row[0] . "\t" . $row[1] . "\t" . $row[2] . "<br>";
print $data;
} while ($row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_PRIOR));
$stmt = null;
}
catch (PDOException $e) {
print $e->getMessage();
}
}
$conn=new PDO('mysql:host=localhost;dbname=bookstore_db', 'root', 'pass');
echo "reading backward<br>";
readDataBackwards($conn);