How To Generate MySQL To RSS (XML) File Used In Google Product Search

Hi Friends, Some days ago I got one requirement for my one client to make RSS or XML file from mysql table to submit into Google Product Search. Google Product Search helps shoppers find and buy products across the web. As a seller, you can submit your products to Google Product Search, allowing shoppers to quickly and easily find your site. So Google Product Search is very useful thing for people who have website of selling online products. Google Product Search supports .txt and .xml (RSS) file. Im my last article I already explained how we can generate MySQL Table To Tab Formatted TXT Datafeed.

For this you have to create one datafeed.xml and save this file where PHP script file is stored.So below is the script by which you can Generate MySQL To RSS (XML) File Used In Google Product Search:

<?php $conn = mysql_connect('hostname', 'username', 'password') or die ('Error connecting to mysql');
mysql_select_db('DB name', $conn) or die ('Error connecting to database');?>
<?php function getXML($sql="Default Query")
$results = mysql_query($sql);

$count = 0;

$data = array();

while ( $row = mysql_fetch_array($results))


$result[$count] = $row;




for($i=0;$i < count($result);$i++)



$columns.= "".$result[$i]['link'];







$content='<?xml version="1.0″?>
<rss version="2.0″ xmlns:g="″>';

$res = update_xml_file($content);

getXML("SELECT id,name,description,price,link,image FROM tablename");

function update_xml_file($content)
$filename = 'datafeed.xml';

if (is_writable($filename))
if (!$handle = fopen($filename, 'w')) {
echo "Cannot open file ($filename)";
// Write $somecontent to our opened file.
if (fwrite($handle, $content) == FALSE) {
$action_msg = "ER";

$action_msg = "SC";
echo "The file $filename is not writable";



If you are having any problems in this script then you can contact me or post problem in comment.

Subscribe to PHP Freelancer

Enter your email address: