douyan1970 2016-04-07 11:08
浏览 176
已采纳

未定义的属性:PDO :: $ affected_rows

after editing my old code to new i get error Undefined property: PDO::$affected_rows and here is the part if ($this->dbCon->affected_rows > 0) can some one help me to solve this problem

class Relation {

private $loggedInUser;
private $dbCon;
public function getRelationship(User $user) {
        $user_one = (int) $this->loggedInUser->getUserId();
        $user_two = (int) $user->getUserId();
        if ($user_one > $user_two) {
            $temp = $user_one;
            $user_one = $user_two;
            $user_two = $temp;
        }
        $resultObj = $this->dbCon->prepare('SELECT * FROM relationship WHERE user_one_id=:user_one AND user_two_id=:user_two');
        $resultObj->execute(array(':user_one' => $user_one,':user_two' => $user_two));
        if ($this->dbCon->affected_rows > 0) {
            $row = $resultObj->fetch(PDO::FETCH_ASSOC);
            $relationship = new Relationship();
            $relationship->arrToRelationship($row, $this->dbCon);
            return $relationship;
        }
        return false;
    }

}}

  • 写回答

1条回答 默认 最新

  • duanjiaolia97750 2016-04-07 11:12
    关注

    A PDO object has no affected_rows property. Instead you can call rowCount() on the PDOStatement:

    if ($resultObj->rowCount() > 0) {
    

    Side note: not all databases support the rowCount() method for SELECT queries, but MySQL does.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hyperledger#的问题,如何解决?
  • ¥30 使用opencv中的solvePnPRansac计算相机位姿后,误差较大
  • ¥15 串口控制LED灯驱动板设计
  • ¥15 如何在unity场景里做到通过按钮实现模型替换
  • ¥15 uniapp的websocket和c++的websocket服务器通讯 发送的数据和接受的数据表现形式不一样
  • ¥15 pyspark配置中的错误
  • ¥15 html word表格
  • ¥15 kali安装包如何解决,请给明确方案和步骤
  • ¥15 DEA软件进行企业创新效率的计算
  • ¥15 树莓派驱动42步进电机