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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀