MySQL to XML Database Dump

Thumb PHP
This code was used to dump a list of legal blogs from a MySQL database to an OPML file.  After the dump, I would typically upload the OPML file to the company’s legal search engine which would then pull the RSS feeds into its own index. I also constructed a spider that would use Google to spider legal blogs for info.
header("Content-type: text/xml");
function check_not_empty($s, $include_whitespace = false)
    if ($include_whitespace) {
        // make it so strings containing white space are treated as empty too
        $s = trim($s);
    return (isset($s) && strlen($s)); // var is set and not an empty string ''
$host = "localhost"; 
$user = ""; //I've erased the username and password for security
$pass = "";
$database = "law";
$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");
$query = "SELECT * FROM blogs2 ORDER BY Serialid ASC";
$resultID = mysql_query($query, $linkID) or die("Data not found.");
$header = "<?xml version=\"1.0\"?>\n
				<opml version=\"1.0\">\n
<title>Matthew Currier created</title>\n
<dateCreated>".date("F j, Y, g:i a")."</dateCreated>\n
echo $header;
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
    $row = mysql_fetch_assoc($resultID);
	$Title = $row['Title'];
	$Htmlurl = $row['Htmlurl'];
	$Xmlurl = $row['Xmlurl'];
	$Serialid = $row['Serialid'];
	$Category1 = $row['Cat1'];
	$Category2 = $row['Cat2'];
	$Category3 = $row['Cat3'];
	$Category4 = $row['Cat4'];
	$Category5 = $row['Cat5'];
	$Category6 = $row['Cat6'];
	$Location1 = $row['Loc1'];
	$Location2 = $row['Loc2'];
	echo "\t<outline type=\"Legal Blogs\" serialID=\"$Serialid\" priority=\"1\" xmlUrl=\"$Xmlurl\" title=\"$Title\" htmlUrl=\"$Htmlurl\" ";
	if (isset($Category1)){ 
	echo "category1=\"".$Category1."\" ";
	if (check_not_empty($Category2)){ 
	echo "category2=\"".$Category2."\" ";
	if (check_not_empty($Category3)){ 
	echo "category3=\"".$Category3."\" ";
	if (check_not_empty($Category4)){ 
	echo "category4=\"".$Category4."\" ";
	if (check_not_empty($Category5)){ 
	echo "category5=\"".$Category5."\" ";
	if (check_not_empty($Category6)){ 
	echo "category6=\"".$Category6."\" ";
	if (check_not_empty($Location1)){ 
	echo "location1=\"".$Location1."\" ";
	if (check_not_empty($Location2)){ 
	echo "location2=\"".$Location2."\" ";
	echo "/>\n";
echo "</body>";
echo "</opml>";
Posted in PHP