I have a table in my database (Mysql) which has 6 columns. I am using PHP forms to store the data in this database. One of the column is for url. I am able to store the data in the database and now I want to construct an XML document with the URL as the data.
Database name: probe_config
table name : webmeasurementsuite
My database details are as follows:
url:(varchar,binary and the default value is null)
replication:(integer,unsigned,zerofill and default value is null)
wait:(integer,unsigned,zerofill and default value is null)
timeout:(integer,unsigned,zerofill and default value is null)
clearcache:(varchar,binary and default value is null)
name:(varchar,binary and default value is null)
id :(integer,notnull,autoinc,unsigned,zerofill and default value is null)
Can anyone help me in converting this to xml document?
Once you get your database results as an array, you can use a function like this to convert that array into an XML document. But do not assume such a function is best performance-wise or software design wise.
Assuming that your database connection is already done,
$sth = $dbh->prepare("SELECT url FROM webmeasurementsuite");
$sth->execute();
$result = $sth->fetchAll();
$xml = '<?xml version="1.0" encoding="UTF-8"?>';
foreach ($result as $v) {
$xml .= '<url>'.htmlspecialchars($v['url'], ENT_COMPAT, 'UTF-8').'</url>';
}
精彩评论