我在使用简单的 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());
}