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)
                {
                        $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)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to