将一个每次显示一条记录的脚本从perl移植到php


Porting a script that displays one record at a time from perl to php

我有一个perl脚本,它一次选择并显示一条记录

my $sth = $dbh->prepare("select * from bar");
/*
bar has 50 records
*/
$sth->execute();
while(my $ref = $sth->fetchrow_hashref()){
print "Current Row is: id = $ref->{'id'},city = $ref->{'city'} 'n";
print "_"x(30) . "'n";
 sleep(10);
}
$sth->finish()

睡眠时间为CCD_ 1秒。

在php中,我正在寻找一种独立于数据库的方式来访问nextprevious记录,而不是像为下一个select * from foo where id = (select min(id) from foo where id > 1) 那样自己编写代码

如何开始移植此代码?。

我这样移植

<?php
$dbh = new PDO('mysql:host=localhost;dbname=odesk', 'root', '123456');
$sth = $dbh->prepare("SELECT job_description from le_jobs_content");
$sth->execute();
while($result = $sth->fetch(PDO::FETCH_ASSOC)){
echo $result['job_description'] .PHP_EOL;
sleep(3);
}
?>