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

未定义的属性: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 Fluent udf 编写问题
  • ¥15 求合并两个字节流VB6代码
  • ¥15 Pyqt 如何正确的关掉Qthread,并且释放其中的锁?
  • ¥30 网站服务器通过node.js部署了一个项目!前端访问失败
  • ¥15 WPS访问权限不足怎么解决
  • ¥15 java幂等控制问题
  • ¥15 海湾GST-DJ-N500
  • ¥15 氧化掩蔽层与注入条件关系
  • ¥15 Django DRF 如何反序列化得到Python对象类型数据
  • ¥15 多数据源与Hystrix的冲突