MySQL无法更新数据库中的行

时间:2016-03-16 14:48:56

标签: php mysql

我正在尝试更新我选择的数据行但我无法更新它。一旦我运行代码,我得到此输出{"RowCount": 0 ,"results": []}。假设我应该得到1,但我没有得到它。我可以知道如何解决这个问题。

这是我的PHP代码:

case 'updateStudent':
$studentUpdateSQL = "UPDATE srs_student SET surname=:surname, forename=:forename,
                    email=:email WHERE studentid=:id";
$rs = new JSONRecordSet();
$retval = $rs->getRecordSet($studentUpdateSQL, 'ResultSet',
          array(':surname'=>$surname,
                ':forename'=>$forename,
                ':email'=>$email,
                ':id'=>$id
            ));
echo $retval;
break;

这是JSONRecordSet类:

function getRecordSet($sql, $elementName = "ResultSet", $params = null) {
    $stmt     = parent::getRecordSet($sql, $params);
    $recordSet = $stmt->fetchAll(PDO::FETCH_ASSOC);
    $nRecords = count($recordSet);
    if ($nRecords == 0) {
        $status = 'error';
        $message = json_encode(array("text" => "No records found"));
        $result = '[]';
    }
    else {
        $status = 'ok';
        $message = json_encode(array("text" => ""));
        $result = json_encode($recordSet);
    }
    return "{\"RowCount\": $nRecords ,\"results\": $result}";
  }
 }

1 个答案:

答案 0 :(得分:0)

reshape