Home · CompatDB.org 1.0 · Mirror List · Examples · FAQ · Support Forums
CompatDB.org

Latest Web News

Latest Linux News

FAQ (Frequently Asked Questions) - How can I implement CompatDB.org in my website/product?

How can I implement CompatDB.org in my website/product?

CompatDB.org is a well-formatted XML based document format and can be parsed easily by many modern programming and scripting languages. Check out the CompatDB.org 1.0 specification for a documentation of all used XML elements.

Here a basic example using PHP 5/simplexml:

<?php

// ---------------------------------------------------------
// CompatDB.org example script for PHP 5
// Written by Philipp Esselbach
//
// This example script is free software and licensed under
// the terms of the GNU Lesser General Public License (LGPL)
// ---------------------------------------------------------

// Get CompatDB.org XML data with simplexml. You can also replace
// this with ntcompatible.compatdb or macoscompatible.compatdb
$compatdb = simplexml_load_file("linuxcompatible.compatdb");
$list = "linux"; // windows, linux, or macos

// Print HTML header
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
echo "<head><title>CompatDB.org Database Example</title>";
echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\" />";
echo "</head><body>";

if (!isset($_GET['product']))
{

// No product id? Let's show the entire compatibility list
echo "<h1>Compatibility list</h1>";
echo "<table><tr>";
echo "<td><strong>Product</strong></td>";
echo "<td><strong>Vendor</strong></td>";
echo "<td><strong>Category</strong></td>";
echo "</tr>";

// Process entries
foreach ($compatdb->entry as $compatdb_entry)
{
echo "<tr><td><a href=\"".$_SERVER['PHP_SELF']."?product=".$compatdb_entry->overview->product_id."\">".$compatdb_entry->overview->product."</td>";
echo "<td>".$compatdb_entry->overview->vendor."</td>";
echo "<td>".$compatdb_entry->overview->category."</td></tr>";
}

echo "</table><br />";
echo "<a href=\"http://www.compatdb.org/compatdbsubmit.php?list=$list\">Click here to submit a result to the compatibility database</a>";

}
else
{

// Ok, we have a product id. Let's process the entries
foreach ($compatdb->entry as $compatdb_entry)
{

// Now we check the entires for the specified product id
if ($compatdb_entry->overview->product_id == intval($_GET['product']))
{

// Let's show the compatibility results for this product id
echo "<h1>Compatibility results for ".$compatdb_entry->overview->product."</h1>";

// See http://www.compatdb.org/faq-96.html for all options
$encoded_product = urlencode($compatdb_entry->overview->product);
$encoded_vendor = urlencode($compatdb_entry->overview->vendor);
echo "<a href=\"http://www.compatdb.org/compatdbsubmit.php?product=$encoded_product&vendor=$encoded_vendor&list=$list\">Submit a result for this product to the database</a><br />";

echo "<a href=\"".$compatdb_entry->overview->compatlink."\">Click here to view the most recent version of this submission</a>";

// Process all submissions
foreach ($compatdb_entry->submission as $compatdb_submission)
{
echo "<hr />";
echo "Tested by ".$compatdb_submission->author." under ".$compatdb_submission->os."<br />";
echo "The author has rated this product with ".$compatdb_submission->rating." out of 5 points<br /><br />";
echo str_replace("\n","<br />",$compatdb_submission->comment);
echo "<br /><br />This entry is licensed under the terms of the ".$compatdb_submission->license;
}

}
}
}

// Print HTML footer
echo "</body></html>";

?>

Here another example using PHP 4 and a MySQL database to store the compatibility data:

1) The first script import the data from the CompatDB.org based XML document to the database:

<?php

// ---------------------------------------------------------
// CompatDB.org MySQL import example script for PHP 4
// Written by Philipp Esselbach
//
// This example script is free software and licensed under
// the terms of the GNU Lesser General Public License (LGPL)
// ---------------------------------------------------------

// Your database configuration
define("DB_HOST", "localhost"); // Database host (usual localhost)
define("DB_USERNAME", "root"); // Database user name
define("DB_PASSWORD", "password"); // Database password
define("DB_DATABASE", "compatdb"); // Database name
define("COMPATDB_XML", "linuxcompatible.compatdb"); // Name of the CompatDB.org based XML document

// Print HTML header
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
echo "<head><title>CompatDB.org MySQL Import</title>";
echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\" />";
echo "</head><body>";

// Let's connect to the database server
mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD) or die("Sorry, but I can not connect to ".DB_USERNAME."@".DB_HOST);
mysql_select_db(DB_DATABASE) or die("Sorry, but I can not select the database ".DB_DATABASE);

// Creating the needed tables
mysql_query("DROP TABLE IF EXISTS compatdb_overview");
echo "Creating table compatdb_overview<br />";
mysql_query("CREATE TABLE compatdb_overview (overview_id int(11), overview_product varchar(255), overview_compatlink varchar(255), overview_vendor varchar(255), overview_vendorlink varchar(255), overview_category varchar(40), overview_created varchar(20), overview_modified varchar(20), PRIMARY KEY (overview_id))");

mysql_query("DROP TABLE IF EXISTS compatdb_submission");
echo "Creating table compatdb_submission<br />";
mysql_query("CREATE TABLE compatdb_submission (submission_id int(11), submission_product int(11), submission_permalink varchar(255), submission_date varchar(20), submission_author varchar(255), submission_language varchar(2), submission_os varchar(40), submission_rating int(5), submission_comment text, submission_license varchar(255), PRIMARY KEY (submission_id))");

// Importing the CompatDB.org based XML document
$compatdb_file = fopen(COMPATDB_XML,"r") or die("Sorry, but I can not open ".COMPATDB_XML);
$xmldata = fread($compatdb_file, filesize(COMPATDB_XML));
fclose($compatdb_file);

// Initalize the XML parser
$compatdb_xml = xml_parser_create();

xml_set_element_handler($compatdb_xml, "compatdb_start", "compatdb_end");
xml_set_character_data_handler($compatdb_xml, "compatdb_parse");

// Let's parse the XML data
echo "Importing data<br />";
xml_parse($compatdb_xml, $xmldata);
xml_parser_free($compatdb_xml);

echo "The data has been successfully imported";

// Print HTML footer
echo "</body></html>";

// Parser start
function compatdb_start($parser, $name, $attrs)
{

global $overview, $submission, $tag;

if ($overview or $submission)
{
$tag = $name;
}
if ($name == "OVERVIEW")
{
$overview = 1;
}
elseif ($name == "SUBMISSION")
{
$submission = 1;
}

}

// Parsing the data
function compatdb_parse($parser, $data)
{

global $tag, $overview, $product, $compatlink, $product_id, $vendor, $vendorlink, $category, $created, $modified, $submission, $permalink, $entry_id, $date, $author, $language, $os, $rating, $comment, $license;

// Process overview section
if ($overview)
{

if ($tag == "PRODUCT")
{
$product .= $data;
}
elseif ($tag == "COMPATLINK")
{
$compatlink .= $data;
}
elseif ($tag == "PRODUCT_ID")
{
$product_id .= $data;
}
elseif ($tag == "VENDOR")
{
$vendor .= $data;
}
elseif ($tag == "VENDORLINK")
{
$vendorlink .= $data;
}
elseif ($tag == "CATEGORY")
{
$category .= $data;
}
elseif ($tag == "CREATED")
{
$created .= $data;
}
elseif ($tag == "MODIFIED")
{
$modified .= $data;
}

}

// Process submission section
if ($submission)
{

if ($tag == "PERMALINK")
{
$permalink .= $data;
}
elseif ($tag == "ENTRY_ID")
{
$entry_id .= $data;
}
elseif ($tag == "DATE")
{
$date .= $data;
}
elseif ($tag == "AUTHOR")
{
$author .= $data;
}
elseif ($tag == "LANGUAGE")
{
$language .= $data;
}
elseif ($tag == "OS")
{
$os .= $data;
}
elseif ($tag == "RATING")
{
$rating .= $data;
}
elseif ($tag == "COMMENT")
{
$comment .= $data;
}
elseif ($tag == "LICENSE")
{
$license .= $data;
}

}

}

// Insert the data to the database
function compatdb_end($parser, $name)
{

global $tag, $overview, $product, $compatlink, $product_id, $vendor, $vendorlink, $category, $created, $modified, $submission, $permalink, $entry_id, $date, $author, $language, $os, $rating, $comment, $license, $this_product;

// Insert the overview data
if ($name == "OVERVIEW")
{

mysql_query("INSERT INTO compatdb_overview VALUES ('".xesc($product_id)."', '".xesc($product)."', '".xesc($compatlink)."', '".xesc($vendor)."', '".xesc($vendorlink)."', '".xesc($category)."', '".xesc($created)."', '".xesc($modified)."')");
$this_product = $product_id;

$product_id = "";
$product = "";
$compatlink = "";
$vendor = "";
$vendorlink = "";
$category = "";
$created = "";
$modified = "";

}

// Insert the submission data
if ($name == "SUBMISSION")
{

mysql_query("INSERT INTO compatdb_submission VALUES ('".xesc($entry_id)."', '".xesc($this_product)."', '".xesc($permalink)."', '".xesc($date)."', '".xesc($author)."', '".xesc($language)."', '".xesc($os)."', '".xesc($rating)."', '".xesc($comment)."', '".xesc($license)."')");

$entry_id = "";
$permalink = "";
$date = "";
$author = "";
$language = "";
$os = "";
$rating = "";
$comment = "";
$license = "";

}

}

// A small function to clean up the XML data for the database
function xesc($var)
{

$var = addslashes(rtrim(ltrim($var)));
return $var;

}

?>


2) The second script is reading the compatibility results from the MySQL database

<?php

// ---------------------------------------------------------
// CompatDB.org MySQL database example script for PHP 4
// Written by Philipp Esselbach
//
// This example script is free software and licensed under
// the terms of the GNU Lesser General Public License (LGPL)
// ---------------------------------------------------------

// Your database configuration
define("DB_HOST", "localhost"); // Database host (usual localhost)
define("DB_USERNAME", "root"); // Database user name
define("DB_PASSWORD", "password"); // Database password
define("DB_DATABASE", "compatdb"); // Database name
$list = "linux"; // windows, linux, or macos

// Print HTML header
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
echo "<head><title>CompatDB.org Database Example</title>";
echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\" />";
echo "</head><body>";

// Let's connect to the database server
mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD) or die("Sorry, but I can not connect to ".DB_USERNAME."@".DB_HOST);
mysql_select_db(DB_DATABASE) or die("Sorry, but I can not select the database ".DB_DATABASE);

if (!isset($_GET['product']))
{

// No product id? Let's show the entire compatibility list
echo "<h1>Compatibility list</h1>";
echo "<table><tr>";
echo "<td><strong>Product</strong></td>";
echo "<td><strong>Vendor</strong></td>";
echo "<td><strong>Category</strong></td>";
echo "</tr>";

// Process entries
$query = mysql_query("SELECT * FROM compatdb_overview");
while($compatdb_overview = mysql_fetch_array($query))
{
echo "<tr><td><a href=\"".$_SERVER['PHP_SELF']."?product=".$compatdb_overview['overview_id']."\">".$compatdb_overview['overview_product']."</td>";
echo "<td>".$compatdb_overview['overview_vendor']."</td>";
echo "<td>".$compatdb_overview['overview_category']."</td></tr>";
}

echo "</table><br />";
echo "<a href=\"http://www.compatdb.org/compatdbsubmit.php?list=$list\">Click here to submit a result to the compatibility database</a>";

}
else
{

// Ok, we have a product id. Let's query the database
$query = mysql_query("SELECT * FROM compatdb_overview WHERE overview_id = '".intval($_GET['product'])."'");
if ($query)
{

$compatdb_overview = mysql_fetch_array($query);
{

echo "<h1>Compatibility results for ".$compatdb_overview['overview_product']."</h1>";

// See http://www.compatdb.org/faq-96.html for all options
$encoded_product = urlencode($compatdb_overview['overview_product']);
$encoded_vendor = urlencode($compatdb_overview['overview_vendor']);
echo "<a href=\"http://www.compatdb.org/compatdbsubmit.php?product=$encoded_product&vendor=$encoded_vendor&list=$list\">Submit a result for this product to the database</a><br />";

echo "<a href=\"".$compatdb_overview['overview_compatlink']."\">Click here to view the most recent version of this submission</a>";

// Show all submissions for that product
$query = mysql_query("SELECT * FROM compatdb_submission WHERE submission_product = '".intval($_GET['product'])."'");
while($compatdb_submission = mysql_fetch_array($query))
{
echo "<hr />";
echo "Tested by ".$compatdb_submission['submission_author']." under ".$compatdb_submission['submission_os']."<br />";
echo "The author has rated this product with ".$compatdb_submission['submission_rating']." out of 5 points<br /><br />";
echo str_replace("\n","<br />",$compatdb_submission['submission_comment']);
echo "<br /><br />This entry is licensed under the terms of the ".$compatdb_submission['submission_license'];
}

}
}
}

// Print HTML footer
echo "</body></html>";

?>

You can download a zip archive with all examples by clicking here

Submitting compatibility results back to CompatDB.org

CompatDB.org have two APIs to allow submitting compatibility results from 3rd party websites and products

1.) The first API is web based. Here an example:

http://www.compatdb.org/compatdbsubmit.php?
> list=windows
> &author=Anonymous
> &bgcolor=cccc99
> &color=000000
> &linkcolor=6B5300
> &vlinkcolor=6B5300
> &font=times+new+roman
> &size=16
> &url=http%3A%2F%2Fwww.majorgeeks.com%2Fcompatibility12739.html
> &product=7-Zip+4.42+%28X64%29
> &vendor=Igor+Pavlov


The following optional parameters are supported:

list
The compatibility list where you like to submit the result: windows, linux, or macos.

author
Author of the submission

bgcolor
Background color of the submission page

color
Font color of the submission page

linkcolor
Color of the links on the submission page

vlinkcolor
Color of the already visited links on the submission page

font
Font used on the submission page. The font name should be encoded with encodeURIcomponent (Javascript) or urlencode (PHP)

size
The size of the font on the submission page

url
The CompatDB.org website will automatically redirect to this URL after the compatibility result has been added to the queue. The URL should be encoded with encodeURIcomponent (Javascript) or urlencode (PHP)

product
Product name. The product name should be encoded with encodeURIcomponent (Javascript) or urlencode (PHP)

vendor
Vendor name. The vendor name should be encoded with encodeURIcomponent (Javascript) or urlencode (PHP)

2.) The second API is email based. The application in question need to send an email in plain text to submissions [at] compatdb [dot] org with the following content (example):

<?xml version="1.0" standalone="yes"?>
<submission>
    <author>Author</author>
    <product>Product name</product>
    <vendor>Vendor</vendor>
    <category>Hardware/General</category>
    <language>en</language>
    <os>Debian GNU/Linux</os>
    <rating>5</rating>
    <comment>This is an example comment</comment>
    <license>GNU Lesser General Public License (LGPL)</license>
</submission>

Here the supported elements in detail:

<author> ... </author>
Author of this entry

<product> ... </product>
Name of the reviewed product

<vendor> ... </vendor>
Name of the product vendor

<category> ... </category>
Product category. The following categories are currently supported:

Applications/Business
Applications/Development
Applications/General
Applications/Graphics
Applications/Internet
Applications/Multimedia
Applications/Network
Applications/Security
Applications/Tools
Games/Action
Games/Adventure
Games/Arcade
Games/Boardgames
Games/General
Games/RPG
Games/Sports
Games/Strategy
Hardware/Audio
Hardware/Camera
Hardware/Controller
Hardware/General
Hardware/Input
Hardware/Motherboard
Hardware/Multimedia
Hardware/Network
Hardware/Notebook
Hardware/Printer
Hardware/Scanner
Hardware/Storage
Hardware/Video

<language> ... </language>
Language in that this entry is written. Currently are the following languages supported:

en (English)
de (German)
fr (French)
es (Spanish)
it (Italian)

<os> ... </os>
Used operating system. The following operating system are currently supported:

Windows:
Windows NT 3.51
Windows NT 4.0
Windows 2000
Windows XP
Windows Server 2003
Windows XP 64 Bit (x86_64)
Windows Server 2003 64 Bit (x86_64)
Windows Vista
Windows Vista 64 Bit (x86_64)

Linux:
Ark Linux
Aurox Linux
CentOS
ClarkConnect
CRUX
Damn Small Linux
Debian GNU/Linux
Fedora Core
Freespire
Gentoo Linux
KANOTIX
KNOPPIX
Libranet GNU/Linux
Linspire
Mandriva Linux
MEPIS Linux
PCLinuxOS
Puppy Linux
Red Hat Linux/RHEL
Slackware Linux
SLAX
SUSE Linux
Trustix
Turbolinux
Ubuntu Linux
Vector Linux
VLOS
Xandros Desktop OS
Yellow Dog Linux
Yoper
Linux other (for not listed distributions)

Mac OS:
Mac OS 9
Mac OS X 10.0 (G3)
Mac OS X 10.0 (G4)
Mac OS X 10.1 (G3)
Mac OS X 10.1 (G4)
Mac OS X 10.2 (G3)
Mac OS X 10.2 (G4)
Mac OS X 10.2 (G5)
Mac OS X 10.3 (G3)
Mac OS X 10.3 (G4)
Mac OS X 10.3 (G5)
Mac OS X 10.4 (G3)
Mac OS X 10.4 (G4)
Mac OS X 10.4 (G5)
Mac OS X 10.4 (Intel)

<rating> ... </rating>
Rating how good the product is running on the specified platform. The following ratings are available:

1... This product is not working at all
2... This product is only party working on my computer configuration
3... This product works, but there are some major issues
4... This product works well, but there are minor problems
5... This product works great, no issues at all

<comment> ... </comment>
A comment what steps are necessary to get the product working and for additional feedback and information

<license> ... </license>
The license name under that this submission is licensed. The system is currently only accepting submissions that are licensed under the terms of the LGPL. You must use here always "GNU Lesser General Public License (LGPL)" or your submission gets automatically rejected


All products mentioned are registered trademarks or trademarks of their respective owners.
© 2007-2008 Esselbach Internet Solutions - All Rights Reserved. Terms and privacy policy
Website powered by Esselbach Storyteller CMS System