//parse xml config file and write items into the specified table in MySQL
function parseConfigFile($xml_file, $mysql_conn, $tb_name)
{
$tbl_count = 0;
$dom=new DOMDocument();
$dom->load($xml_file);
foreach($dom->getElementsByTagname('feed') as $feed)
{
$table_name = $feed->getElementsByTagname('table');
$table_value = $table_name->item(0)->firstChild->nodeValue;
echo $table_value.'<br />';
//first query the specified rss link from feedUrl table if exist?
$query = 'SELECT tbl_name FROM '.$tb_name.' WHERE tbl_name="'.$table_value.'"';
echo $query.'<br />';
$result = mysql_query($query,$mysql_conn);
var_dump($result);
echo '<br />';
$row = mysql_num_rows($result);
echo $row.'<br />';
mysql_free_result($result);
$query = null;
$result = null;
var_dump($result);
echo '<br />';
if($row)
{
echo 'already exist a table item '.$table_value.' in the current table, count number '.$tbl_count;
echo '<br />';
continue;
}
else
{
echo 'I am coming in';
//if no exist, insert this record into data table feedUrl
$insert_query = "INSERT INTO ".$tb_name." (tbl_name,last_update) VALUES ('".$table_value."', NOW())";
echo $insert_query.'<br />';
$insert_result = mysql_query($insert_query,$mysql_conn);
if($insert_result == 1)
{
$tbl_count++;
echo 'write a record ok';
}
else
echo $insert_result.mysql_error();
echo '<br />';
}
//mysql_free_result($result);
}
echo 'already load all tables with the total number '.$tbl_count;
} 作者: tao_627 时间: 2012-05-26 14:26 本帖最后由 tao_627 于 2012-05-26 14:27 编辑