开发者

PHP equivalent for .NET's DataTable.Select(expression)?

I'm going to optimize the data access layer of my php web application. Currently, my php web application makes a lot of queries (some possibly redundant) to the database. I want to reduce the number of queries to the database by writing only a few more complex queries that return larger and more generic data sets. I then want to store these results in the $GLOBALS variable.

Then I can access the data elsewhere in my web application like so:

$GLOBALS['dbResults1'] = $dbObject->get();
$result = new ResultWrapper($GLOBALS['dbResults1']);
$array_eligible_athletes = $result->Select(' age > 20 ');
$array_obese = $result->Select(' bmi > 100 ')->orderBy('lastname,firstname desc');
etc...

as opposed to my current way of:

// each of these makes a trip to the database
$array_eligible_athletes = $dbObject->getWhere('age > 20'); 
开发者_开发百科$array_obese = $dbObject->getWhere('bmi > 100')->orderBy('lastname,firstname desc');
etc...

So my questions are:

1) Is my new approach a good idea? What is the likelihood my new approach will improve the performance of my web application?

2) If 1) is a good idea, are there libraries out there that do what I want? Ie. a better way of querying and managing datasets.

I really enjoyed the DataTable.Select() feature in the .Net framework, and was hoping for something similar in PHP development. If one doesn't exist, anything solution that helps me reduce calls to db would be great.


  1. Depends. Always. Profile.
  2. You could try something like array_filter to replace DataTable.Select for a built-in solution.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜