Skip to content

Instantly share code, notes, and snippets.

@onpubcom
Created February 7, 2012 00:06
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/1756059 to your computer and use it in GitHub Desktop.
Save onpubcom/1756059 to your computer and use it in GitHub Desktop.
<?php
// Include the Onpub API files.
include 'onpub/api/onpubapi.php';
try {
// Connect to the Onpub database.
// Replace host, dbname, username, and password with your own DB connection
// info.
$pdo = new PDO( "mysql:host=localhost;dbname=test", "test", "test" );
}
catch ( PDOException $e ) {
// Database connection error.
echo $e->getMessage();
exit(1);
}
// Construct the OnpubArticles object using the PDO connection.
// In an abstract sense the OnpubArticles object represents the OnpubArticles
// MySQL table in the Onpub database.
$oarticles = new OnpubArticles($pdo);
// Use the OnpubArticles object to get a specific article from the database
// using its ID, which is 1 in this example.
$article = $oarticles->get(1);
// The $article variable now holds an OnpubArticle object. This variable will
// be NULL if there was no article with ID 1 in the database. You can now
// use the OnpubArticle object to output the Article's properties.
echo $article->title . '<br>';
echo $article->content;
// Articles also have other properties you can output. They are all documented
// here:
// http://onpubco.com/onpubapiref/OnpubAPI/OnpubArticle.html#sec-var-summary
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment