Friday, July 30, 2010
 

eZ Components database abstraction more querys examples

This time i will share more examples of sql queries using eZ Components. So let's start

Initial documentation of database abstraction can be found at http://ezcomponents.org/docs/api/trunk/introduction_Database.html and http://ezcomponents.org/docs/api/trunk/introduction_PersistentObject.html I will paste more examples that can be usfull starting programming with eZ Components.

First examples is simple SQL COUNT query. Example:

$currentUser = erLhcoreClassUser::instance();
       
$session = erLhcoreClassRSS::getSession();
$q = $session->database->createSelectQuery();  
$q->select( "COUNT(*)" )->from( "lh_rss_feed" ); 
$q->where( 
          $q->expr->eq( 'user_id', $currentUser->getUserID())
           );
$stmt = $q->prepare();
$stmt->execute();                    
      
$numberOfRecords = $stmt->fetchColumn();

 Iterative object list fetching example:

$session = erLhcoreClassRSS::getSession();
$q = $session->createFindQuery( 'erLhcoreClassModelRSSFeed' ); 
$objects = $session->findIterator( $q, 'erLhcoreClassModelRSSFeed' );         

 

Back »

Comments: 0

Leave a reply »

 
  • Leave a Reply
    Your gravatar
    Your Name
     
     
     
     
     
 
About Remdex site

Simple site for simple peoples.

Get in touch

E-mail: remdex@gmail.com