On Tue, Feb 22, 2011 at 1:07 PM, Florin Jurcovici
<florin.jurcov...@gmail.com> 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)
>

Reply via email to