Skip to content

Instantly share code, notes, and snippets.

@onpubcom
Created February 7, 2012 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onpubcom/1756118 to your computer and use it in GitHub Desktop.
Save onpubcom/1756118 to your computer and use it in GitHub Desktop.
<?php
// Establish the connection to the Onpub database.
$pdo = new PDO( "mysql:host=localhost;dbname=test", "test", "test" );
// Include the OnpubAPI classes.
include 'onpub/api/onpubapi.php';
// Construct an OnpubArticles object. This represents the OnpubArticles table
// in the database.
$oarticles = new OnpubArticles($pdo);
// Create a query options object. We will use this to order the articles to
// be selected below by date (newest to oldest).
$qo = new OnpubQueryOptions();
$qo->orderBy = 'created';
$qo->order = 'DESC';
// Limit the result to only 1 row from the database.
$qo->rowLimit = 1;
// Now let's select the latest article from section ID 2. Change the second
// argument (2) to the section ID number you want to select the article from.
$articles = $oarticles->select($qo, 2);
// Since the above method returned an array with one result, let's copy that
// result to a new variable.
$article = $articles[0];
// Now let's print out some of the article object's fields.
en('<b>ID</b>: ' . $article->ID, 1, 2);
en('<b>Title</b>: ' . $article->title, 1, 2);
en('<b>Content</b>:<br>' . $article->content, 1, 1);
en('<b>Created</b>: ' . $article->getCreated()->format('M j, Y, g:i a'));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment