make the pdo fetch style configurable.

This commit is contained in:
Taylor Otwell
2012-02-24 11:35:02 -06:00
parent 9804bb55dc
commit 484a737382
3 changed files with 41 additions and 6 deletions

View File

@@ -145,7 +145,7 @@ class Connection {
// and deletes we will return the affected row count.
if (stripos($sql, 'select') === 0)
{
return $statement->fetchAll(PDO::FETCH_CLASS, 'stdClass');
return $this->fetch($statement, Config::get('database.fetch'));
}
elseif (stripos($sql, 'update') === 0 or stripos($sql, 'delete') === 0)
{
@@ -212,6 +212,28 @@ class Connection {
return array($statement, $result);
}
/**
* Fetch all of the rows for a given statement.
*
* @param PDOStatement $statement
* @param int $style
* @return array
*/
protected function fetch($statement, $style)
{
// If the fetch style is "class", we'll hydrate an array of PHP
// stdClass objects as generic containers for the query rows,
// otherwise we'll just use the fetch styel value.
if ($style === PDO::FETCH_CLASS)
{
return $statement->fetchAll(PDO::FETCH_CLASS, 'stdClass');
}
else
{
return $statement->fetchAll($style);
}
}
/**
* Log the query and fire the core query event.
*