New enhancement in the old pattern

I gone through one of my old project. Some of the points I noticed to enhance and simplify the code.

-Combine methods into single method to achieve the same fuctionality.

As we are using the PEAR DB package to query to database. I thought to have a map of all the queries into any Array .

Steps I will follow to achieve the same is

-Create Map of queries

$queryMap = array (“getPerson”=>”SELECT * FROM person WHERE personID = “, “getPersonList”=>”SELECT * FROM person”)

-One method which will just run query and returns its output

function getData($query, $ID=0)
{
$result = $db->query(queryMap[$query].” “.$ID);
return $db->fetchRow();
}
function getAllData($query)
{
return $result = $db->getAll(queryMap[$query]);

}

I will be implementing it in my new project.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: