현재 PHP로 작성된 스크립트 (phpMyAdmin
)에 데이터베이스에 연결 한 다음 모든 테이블 값을 XML 문서로 구문 분석합니다.PHP로 XML 파일 생성/쓰기?
$xmlBody .= "<XML>";
$sql_news = mysql_query("SELECT * FROM news_table");
$xmlBody .= "<News_Table>";
//this while loop churns out the values of our "news_table" table
while($row_news = mysql_fetch_array($sql_news)){
// Set DB variables into local variables for easier use
$id_news = $row_news["news_id"];
$author_news = $row_news["news_author"];
$time_news = $row_news["news_time"];
$title_news = $row_news["news_title"];
$content_news = $row_news["news_content"];
$desc_news = $row_news["news_description"];
$image_news = $row_news["news_image"];
$xmlBody .= '
<News_Table_Entry>
<DataID>' . $id_news . '</DataID>
<DataAuthor>' . $author_news . '</DataAuthor>
<DataTime>' . $time_news . '</DataTime>
<DataTitle>' . $title_news . '</DataTitle>
<DataContent>' . $content_news . '</DataContent>
<DataDesc>' . $desc_news . '</DataDesc>
<DataImage>' . $image_news . '</DataImage>
</News_Table_Entry>';
} // End while loop
$xmlBody .= "</News_Table>";
mysql_close(); // close the mysql database connection
$xmlBody .= "</XML>";
echo $xmlBody;
?>
가 어떻게 외부 XML file
으로이를 작성하고 출력 할 : 여기
스크립트가 작동하는 방법입니까? 나는이 스크립트가 성공적으로 작동하도록 만들었지 만, XML에 쓰는 모든 메소드를 사용하는 것은 작동하지 않습니다.
echo 'Wrote: ' . $doc->save("/tmp/test.xml") . ' bytes'; // Wrote: 72 bytes
fwrite 기능과 함께 기능이 작동하지 않습니다. 나는 이것을 며칠 동안 알아 내려고 노력해 왔지만, 시도해 보았던 해결책 중 어느 것도 효과가 없었다. 어떤 도움이나 통찰력이라도 대단히 감사하겠습니다!
확장 성 및 유지 관리를 위해 일련 번호를 조사해야합니다. http://pear.php.net/package/XML_Serializer/redirected –
'$ doc'을 (를) 확인하십시오. 당신은'DOMDocument' 또는'SimpleXML'을 사용하고 있지 않습니까? 그러므로'save' 메쏘드는 정의되어 있지 않습니다. – Raptor
해결책을 얻으시겠습니까? –