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 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测