致命错误:调用未定义的方法PDOStatement :: fetch_row()

时间:2013-02-12 23:12:46

标签: php mysql

我可以做些什么来修复我的代码?运行程序时出现以下错误消息:

  

致命错误:在第12行的C:\ apache2 \ Apache2 \ htdocs \ ch \ ch32 \ listing32_2(1).php中调用未定义的方法PDOStatement :: fetch_row()

<?php

    // Instantiate the mysqli class
    $db = new PDO("mysql:host=localhost;dbname=coorporate", "root", "xxxxxxxx");

    // Assign the employeeID
    $eid = htmlentities($_POST['id']);

    // Execute the stored procedure 
    $result = $db->query("SELECT calculate_bonus('$eid')");

    $row = $result->fetch_row();

    printf("Your bonus is \$%01.2f",$row[0]);
?>

2 个答案:

答案 0 :(得分:2)

在PDOStatement中不存在fetch_row方法 - 你必须使用PDOStatement::fetch(PDO::FETCH_NUM)

答案 1 :(得分:0)

您需要PDOStatement::fetch,没有fetch_row()

$row = $result->fetch_row();应为$row = $result->fetch();

相关问题