eZ Components database abstraction more querys examples
2009-12-29 19:49
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 »