Sep 27 2007

Some More About Propel

Propel Random Criteria >>

$c= new Criteria();
$c->addAscendingOrderByColumn('rand()');
$TagRs = TagPeer::doSelect($c );

?>

This code will give you the result in random manner. Here in this example, i show the random tags from Tag Table.

Propel Memory Optimization using Result Set >>

if you use

$TagRs= TagPeer::doSelect(new Criteria());

The whole result of the query will be saved in $TagRs as array (Means usage of memory to save whole the table rows).
But if you want two columns of this table, the rest are wastage of memory. In that case you can use result set after selecting the
desired columns.

Eg:

$c = new Criteria();
$c->addSelectColumn(FilePeer::FILETAG);
$c->addSelectColumn(FilePeer::TITLE);
$FileRs = FilePeer::doSelectRS($c);

foreach($FileRs as $FileR)
{

$Tag = $FileR[0]; // Here the first column is the tag
$Title= $FileR[1]; //Second column is the title
}

Here you saves the memory, since $FileRs contains only two columns information.

Propel Set Limit >>

If you want to set a limitation for your query results, you can use setLimit function.

Eg:

$c = new Criteria();
$c->setLimit(10);

$FileRs = FilePeer::doSelectRS($c);

Here the Array $FileRs only contains 10 records. Thus you can limit the query results.

Propel Set Offset >>

If you want the results of a particular query , from a cetain offset, you can use offset function.

Eg:

// Select Random 3 images

$random = rand(0,$TotalCountImages);
$c=new Criteria();
$c->addDescendingOrderByColumn(FilePeer::ID);

$c->add(FilePeer::APPROVED,-1,Criteria::NOT_EQUAL);

$c->add(FilePeer::FTYPE,'IMAGE' );

$c->setOffset($random);
$c->setLimit(3);

$RelatedRs = FilePeer::doSelect($c);

//Here the relatedRs will start from a random offset. (Not from the begining as usual query results)

TAGS:

1 Comments on this post

Trackbacks

  1. mrsajith said:

    For symfony users, this link will be useful:
    http://www.symfony-project.com/book/1_0/18-Performance

    September 28th, 2007 at 3:34 pm

LEAVE A COMMENT

Subscribe Form

Subscribe to Blog

Sponsors

    Itslife Online
    Advt on sajithmr.com
    Advt on sajithmr.com
    Advt on sajithmr.com

Recent Comments

  • Binny V A: Thanks for the post - love the picture ;-)
  • TheAnand: A lot of people are seeing errors with google video chat….is there any other software which has to be...
  • Alex: Wow, interresting analysis you have done! I’m trying to run GoogleVoiceAndVideoSetup on linux, using...
  • Mella Fitriansyah: Nice plugin, I will try to add this plugin in my blog…
  • Mella Fitriansyah: Nice Info, Sir i will reading your another post success for you

Recent Readers

JOIN MY COMMUNITY!

Recent Posts