From cc25349d3035938d2b1878776012e604d511a83a Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 15 Aug 2012 11:07:12 +0200 Subject: [PATCH] Implement PDO in object retrieval --- class.databaserecord.php | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/class.databaserecord.php b/class.databaserecord.php index 16943be..4ef493a 100644 --- a/class.databaserecord.php +++ b/class.databaserecord.php @@ -99,6 +99,8 @@ abstract class CPHPDatabaseRecordClass extends CPHPBaseClass public function ConstructDataset($uDataSource, $defaultable = null) { + global $database; + $bind_datasets = true; if(is_numeric($uDataSource)) @@ -109,15 +111,32 @@ abstract class CPHPDatabaseRecordClass extends CPHPBaseClass { $this->sId = (is_numeric($uDataSource)) ? $uDataSource : 0; - $query = sprintf($this->fill_query, $uDataSource); - if($result = mysql_query_cached($query, $this->query_cache)) + if(strpos($this->fill_query, " :") === false) { - $uDataSource = $result->data[0]; + /* Use mysql_* to fetch the object from the database. */ + $query = sprintf($this->fill_query, $uDataSource); + if($result = mysql_query_cached($query, $this->query_cache)) + { + $uDataSource = $result->data[0]; + } + else + { + $classname = get_class($this); + throw new NotFoundException("Could not locate {$classname} {$uDataSource} in database.", 0, null, ""); + } } else { - $classname = get_class($this); - throw new NotFoundException("Could not locate {$classname} {$uDataSource} in database.", 0, null, ""); + /* Use PDO to fetch the object from the database. */ + if($result = $database->CachedQuery($this->fill_query, array(":Id" => $this->sId), $this->query_cache)) + { + $uDataSource = $result->data[0]; + } + else + { + $classname = get_class($this); + throw new NotFoundException("Could not locate {$classname} {$uDataSource} in database.", 0, null, ""); + } } } else