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 Ubuntu20.04.4.LTS系统如何下载安装VirtualBox虚拟机?
  • ¥15 如何用QDomDocument读取内容为空格的xml数据
  • ¥15 请阅读下面代码,帮我修改下代码
  • ¥15 关于#microsoft#的问题:电脑启动后不显示桌面图标和窗口,除任务栏外无法操作任何东西
  • ¥15 如何输入百度,显示本地下载的html文件页面,地址栏还显示百度的地址
  • ¥15 通过kinect制作换装程序但是服装不贴合(标签-ar)
  • ¥20 matlab如何绘制三维瀑布图
  • ¥15 关于用abap来解决动态规划的问题,但是要求输出索引值,这个是难点
  • ¥15 在ISIS中什么是IP从地址
  • ¥15 压测时,并发量过高时,响应时间出现尖刺