how use mysql_data_seek with PDO?

后端 未结 4 1712
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-04 22:57

I want use mysql_data_seek with PDO from google search I found that it should looks like this:

$row0 = $result->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_ABS         


        
4条回答
  •  误落风尘
    2021-01-04 23:49

    the PDO 'cursor' default is PDO::CURSOR_FWDONLY that means that cursor can't back to zero like it happens with mysql_data_seek to allow cursor back to zero it necessary define use 'scrollable cursor'

    example:

    $db->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
    

    before use it like this:

    $row0 = $result->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_ABS, 0);
    

提交回复
热议问题