mirror of
https://github.com/standardebooks/web.git
synced 2025-07-07 15:20:32 -04:00
Allow for an object's own FromRow method in DbConnection
This commit is contained in:
parent
50efeb05d1
commit
97cafbf128
1 changed files with 14 additions and 2 deletions
|
@ -171,8 +171,15 @@ class DbConnection{
|
||||||
|
|
||||||
$rows = $handle->fetchAll(\PDO::FETCH_NUM);
|
$rows = $handle->fetchAll(\PDO::FETCH_NUM);
|
||||||
|
|
||||||
|
$useObjectFillMethod = method_exists($class, 'FromRow');
|
||||||
|
|
||||||
foreach($rows as $row){
|
foreach($rows as $row){
|
||||||
$object = new $class();
|
if($useObjectFillMethod){
|
||||||
|
$object = new stdClass();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$object = new $class();
|
||||||
|
}
|
||||||
|
|
||||||
for($i = 0; $i < $handle->columnCount(); $i++){
|
for($i = 0; $i < $handle->columnCount(); $i++){
|
||||||
if($metadata[$i] === false){
|
if($metadata[$i] === false){
|
||||||
|
@ -246,7 +253,12 @@ class DbConnection{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result[] = $object;
|
if($useObjectFillMethod){
|
||||||
|
$result[] = $class::FromRow($object);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$result[] = $object;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(\PDOException $ex){
|
catch(\PDOException $ex){
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue