On Tue, Feb 22, 2011 at 1:07 PM, Florin Jurcovici <florin.jurcovici@xxxxxxxxx> wrote: > Hi. > > I use PDO and have written myself a class to abstract the database a bit. > > It has a method for querying the database specifically for large > objects, like this: > > Â Â Â Â Â Â Â Â$connection = $this->getConnection(); Â // what's returned is a > PDOStatement, and a transaction is already started > Â Â Â Â Â Â Â Â$statement = $connection->prepare($sql); > Â Â Â Â Â Â Â Â$result = true; > Â Â Â Â Â Â Â Âforeach ($parameters as $key => $parameter) > Â Â Â Â Â Â Â Â Â Â Â Â$statement->bindValue($key, $parameter->value, $parameter->type); > Â Â Â Â Â Â Â Âtry > Â Â Â Â Â Â Â Â{ > Â Â Â Â Â Â Â Â Â Â Â Â$result = $statement->execute(); > Â Â Â Â Â Â Â Â} > Â Â Â Â Â Â Â Âcatch(Exception $ex) Wrong catch? [1] Regards, Tommy [1] http://php.net/pdoexception > Â Â Â Â Â Â Â Â{ > Â Â Â Â Â Â Â Â Â Â Â Â$statement->closeCursor(); > Â Â Â Â Â Â Â Â Â Â Â Âthrow $ex; > Â Â Â Â Â Â Â Â} > Â Â Â Â Â Â Â Âif (!$result) > Â Â Â Â Â Â Â Â{ > Â Â Â Â Â Â Â Â Â Â Â Â$statement->closeCursor(); > Â Â Â Â Â Â Â Â Â Â Â Âthrow new Exception("SQL statement failed: ".$sql); > Â Â Â Â Â Â Â Â} > Â Â Â Â Â Â Â Â$data = array(); > Â Â Â Â Â Â Â Â$receiverRow = array(); > Â Â Â Â Â Â Â Â$i = 0; > Â Â Â Â Â Â Â Âforeach ($columns as $column => $type) > Â Â Â Â Â Â Â Â{ > Â Â Â Â Â Â Â Â Â Â Â Â$receiverRow[$column] = NULL; Â // this is probably not necessary, I > added it after it didn't work without, but it didn't help > Â Â Â Â Â Â Â Â Â Â Â Â$statement->bindColumn($i++, &$receiverRow[$column], $type); > Â Â Â Â Â Â Â Â} > Â Â Â Â Â Â Â Âwhile ($statement->fetch(PDO::FETCH_BOUND)) > Â Â Â Â Â Â Â Â{ > Â Â Â Â Â Â Â Â Â Â Â Â$row = array(); > Â Â Â Â Â Â Â Â Â Â Â Âforeach ($columns as $column => $type) > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â$row[$column] = $receiverRow[$column]; > Â Â Â Â Â Â Â Â Â Â Â Â$data[] = $row; > Â Â Â Â Â Â Â Â} > Â Â Â Â Â Â Â Â$statement->closeCursor(); > Â Â Â Â Â Â Â Âreturn $data; > > The problem is, after $statement-> execute() the first fetch returns > false, although there's definitely a record in there - > $statement->rowCount() says 1, if called before $statement->fetch(). > No exception is thrown, $statement->errorInfo() and > $statement->errorCode don't contain anything useful. > > What am I doing wrong? > > br, > > flj > > -- > Fine counsel is confusing, but example is always clear. (Edgar A. > Guest, The Light of Faith) >