how use mysql_data_seek with PDO?

后端 未结 4 1680
佛祖请我去吃肉
佛祖请我去吃肉 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:51

    If you want the 5th row result you can do like this:

    $result = json_decode(json_encode($arrayData[4]), FALSE);
    var_dump($result);
    

    or something like this:

    $object = new stdClass();
    foreach ($array as $key => $value)
    {
        $object->$key = $value;
    }
    

    Just curious! why do you need the object form?

    EDIT (this will give the object form of the 5th row):

    $index = 0;
    $fifthRow = new stdClass();
    while($row = $q->fetch())
    {
       if($index++==4)
            $fifthRow = json_decode(json_encode($row), FALSE);
    }   
    

提交回复
热议问题