douhao2721 2013-02-18 23:13
浏览 32
已采纳

PHP PDO mysql_data_seek

I'm converting some code to access a database to PDO. I've come across the following:

mysql_data_seek($result, 0);
$row0 = mysql_fetch_assoc($result);

And from my readings on Google etc, I understand this should be:

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

however this isn't working. Any ideas what i'm doing wrong?

  • 写回答

2条回答 默认 最新

  • dongpuchao1680 2013-02-18 23:48
    关注

    From manual;

    Fetches a row from a result set associated with a PDOStatement object. The fetch_style parameter determines how PDO returns the row.

    You need a stmt that was created by PDO::prepare method.

    Let's see this;

    // assuming $pdo was created before as well
    $sth = $pdo->prepare("SELECT name, colour FROM fruit");
    // exec here
    $sth->execute();
    // get a row here
    $row = $sth->fetch(PDO::FETCH_ASSOC);
    // here probably you'll get a print out like
    // Array([name] => Banana, [color] => Yellow)
    print_r($row);
    

    See more details here: PHP PDOStatement::fetch

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试