PHP PDO获取错误。rowcount=1,但fetchall返回false;

PHP PDO获取错误。rowcount=1,但fetchall返回false;,php,mysql,sql,pdo,fetch,Php,Mysql,Sql,Pdo,Fetch,我在使用简单的select sql查询时遇到了问题。 使用php PDO 出于某种原因,rowcount返回1,但fetch和fetchall都返回false; 对我来说,这意味着执行失败,或者查询没有返回行数为0的结果。据我所知,我的sql语法很好 下面是sql查询 SELECT * FROM CustomerAddress WHERE ".CustomerAddress::custAddressID." = :".CustomerAddress::custAddressID." LIMIT

我在使用简单的select sql查询时遇到了问题。 使用php PDO

出于某种原因,rowcount返回1,但fetch和fetchall都返回false; 对我来说,这意味着执行失败,或者查询没有返回行数为0的结果。据我所知,我的sql语法很好

下面是sql查询

SELECT * FROM CustomerAddress WHERE ".CustomerAddress::custAddressID." = :".CustomerAddress::custAddressID." LIMIT 1
这是代码

try{
        if($this->selectCustomerAddressStatement->execute(array(CustomerAddress::custAddressID => $addressID)))
        {
            if($this->selectCustomerAddressStatement->rowCount() == 1)
            {   
                $this->selectCustomerAddressStatement->closeCursor();
                if($temp = $this->selectCustomerAddressStatement->fetch())
                {
                    $customerAddress = new CustomerAddress($temp);
                    if($customerAddress->getCustAddressID() == $addressID)
                    {
                        return $customerAddress;
                    }else{
                        throw new Exception("The Customer Address Retrieved was not what was Asked.");
                    }
                }else{
                    throw new Exception("Failed to retrieve Result set.");
                }
            }else{
                throw new Exception("Statement Returned To Many Results.");
            }
        }else{
            throw new Exception("Failed to Execute Statement.");
        }
    }catch(Exception $e) {
        $this->selectCustomerAddressStatement->closeCursor();
        throw new Exception("Customers:: selectCustomerAddress - ".$e->getMessage());
    }

看起来问题是:

$this->selectCustomerAddressStatement->closeCursor();

。。在行计数之后调用。关闭游标可能会释放语句的结果,这就是为什么抓取不会返回任何结果。提取完数据后,将调用移动到最后。

天哪,我不敢相信我从未注意到这一点。在那里坐了2个小时,想着wtf。非常感谢。