2011-02-28 114 views
-1

我有一個表在我的數據庫(Mysql)有6列。我正在使用PHP表單將數據存儲在此數據庫中。其中一列是url。我能夠將數據存儲在數據庫中,現在我想構建一個URL作爲數據的XML文檔。xml文檔的創建

Database name: probe_config 
table name : webmeasurementsuite 

我的數據庫詳情如下:

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) 

誰能幫我在這轉換成XML文件?

回答

0

將數據庫結果作爲數組獲取後,可以使用函數like this將該數組轉換爲XML文檔。但不要認爲這樣的功能是最好的性能或軟件設計明智的。

假設你的數據庫連接已經完成,

$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>'; 
} 
+0

thanks..Shall我知道如何將數據庫結果轉換爲一個數組?我能舉一個例子嗎? – 2011-03-01 08:43:25

+0

謝謝..我想知道在哪裏插入它。如果插入它,我應該插入它在我的PHP編碼。 – 2011-03-02 04:30:09

+0

是的,你應該把它放到你的PHP代碼中。 – 2011-03-02 07:15:23