Created
February 7, 2012 00:06
-
-
Save onpubcom/1756059 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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