1

単純な選択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());
    }
4

1 に答える 1

2

問題は次のとおりです。

$this->selectCustomerAddressStatement->closeCursor();

.. 行数の後に呼び出されます。カーソルを閉じると、ステートメントの結果が解放される可能性があります。これが、フェッチが何も返さない理由です。データのフェッチが完了したら、その呼び出しを最後に移動します。

于 2010-09-07T04:32:09.297 に答える