I have two methods which are 90% identical, ie 90% repetitive code. I am trying to extend the 2nd method.
First Method:
public function getResultsByID($userID = null){
$sqlParams = array();
if (!$userID)
{
throw new Exception("No User ID Provided");
}
$sqlParams['userID'] = $userID;
$sql = "SELECT t.user_id,
t.owner_id,
t.store_id
FROM users t
LEFT JOIN store s
ON s.store_id = t.store_id
WHERE t.user_id = :userID";
$db = $this->dbWrite : $this->dbRead;
$results = $db->getRow($sql, $sqlParams);
return $results;
}
My Second method is pretty identical except that I am joining multiple tables into this.
public function getMoreResultsByID($userID = null){
$sqlParams = array();
if (!$userID)
{
throw new Exception("No User ID Provided");
}
$sqlParams['userID'] = $userID;
$sql = "SELECT t.user_id,
t.owner_id,
t.store_id
FROM users t
LEFT JOIN store s ON s.store_id = t.store_id
LEFT JOIN owner_contact oc ON oc.owner_id = t.owner_id
LEFT JOIN owner_detail od ON od.owner_id = t.owner_id
WHERE t.user_id = :userID";
$db = $this->dbWrite : $this->dbRead;
$results = $db->getRow($sql, $sqlParams);
return $results;
}
I am unable to figure out how to extend my getMoreResultsByID() from getResultsByID() so that I can get rid of identical code
Thanks in advance