<?

$hostname = 'mySite.com';
$username = 'userName';
$password = 'passWord';
$database = 'databaseName';

// *** DATABRIDGE v 1.0 ***
//
// This small php file acts as a bridge between the KRecordSet component
// and a MySQL database.
// You should fill in $hostname, $username, $password & $database
// for it to function.
// 
// As a protection this bridge currently only allows select queries.
// If you want to add functionality to insert new data into your database
// change max-age=600 to max-age=0
// and delete the line
//   if(!eregi("^ *select .+ from .+",$query)) die();
// in the connect to database section below
// but remember it involves a risk.

// *** cache & xml headers *** 

header("Cache-control: max-age=600, must-revalidate"); 
header("Content-Type: text/xml");

// *** connect to database and output query as xml document ***

set_magic_quotes_runtime(0);
if(get_magic_quotes_gpc()) $query=stripslashes($query);
if(!eregi("^ *select .+ from .+",$query)) die();
@mysql_connect($hostname,$username,$password) or die();
$result=mysql_db_query($database,$query) or die();

echo('<?xml version="1.0" encoding="UTF-8"?>');
echo("\n<recordset>\n");
while($record=mysql_fetch_assoc($result)){
  echo("<record>\n");
  foreach ($record as $fieldname => $value) {
    echo(utf8_encode("<$fieldname>"));
	  echo(utf8_encode(htmlspecialchars(str_replace("\r","",$value))));
    echo(utf8_encode("</$fieldname>\n"));
  }
  echo("</record>\n");
}
echo("</recordset>\n"); 

?>
